-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
76 lines (55 loc) · 1.72 KB
/
signup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
ob_start();
include 'inc/navbar.php';
if (isset($_SESSION['used_id'])) {
header('Location: index.php');
exit;
}
$error = "";
if (isset($_POST['submit'])) {
$error = "";
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE email = '$email'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
$error = "Email already in use.";
} else {
$query = "INSERT INTO users (name, email, password) VALUES ('$name', '$email', '$password')";
$result = mysqli_query($conn, $query);
if ($result) {
$id = mysqli_insert_id($conn);
$_SESSION['user_id'] = $id;
setcookie('name', $name, time() + 60 * 60 * 24 * 30);
setcookie('email', $email, time() + 60 * 60 * 24 * 30);
header('Location: index.php');
exit;
} else {
echo 'Error occured';
}
}
mysqli_close($conn);
}
ob_end_flush();
?>
<div class="auth-container">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" class="auth-form">
<h1>Signup</h1>
<div>
<label for="name">Name</label>
<input type="text" name="name" required>
</div>
<div>
<label for="email">Email</label>
<input type="email" name="email" required>
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" required>
</div>
<input type="submit" value="Submit" name="submit">
<p><?php echo $error?></p>
<a href="login.php">Click here to login</a>
</form>
</div>