-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
124 lines (109 loc) · 4.37 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
include("connect.php");
session_start();
$email = $password = "";
$errors = ["email" => "", "password" => ""];
$error = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
if (empty($_POST["email"])) {
$errors["email"] = "An email is required. <br/>";
} else {
$email = htmlspecialchars($_POST["email"]);
}
if (empty($_POST["password"])) {
$errors["password"] = "An password is required. <br/>";
} else {
$password = htmlspecialchars($_POST["password"]);
}
if (!array_filter($errors)) {
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$sql = "SELECT user_id FROM user WHERE email = '$email';";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
// If result matched $email and $password, table row must be 1 row
if ($count > 0) {
//user already exist
$sql = "SELECT user_id FROM user WHERE email = '$email' AND password = '$password';";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if ($count == 1) {
//already exist and valid credentials
// so log it in
$_SESSION['login_user_email'] = $email;
header("Location: index.php");
} else {
//already exist but not valid cred.
$error = "User already exist, use another email.";
}
} else {
//new user
$sql = "INSERT INTO user(email,password) VALUES('$email','$password');";
if (mysqli_query($conn, $sql)) {
//successfully signed up
$_SESSION['login_user_email'] = $email;
header("Location: index.php");
} else {
//error in creating user
echo "Create user error: " . mysqli_error($conn);
}
}
}
}
?>
<?php include "header.php"; ?>
<div class="banner_blur ">
<div class="flex-1 min-w-0 p-5 ">
<div class="text-4xl text-gray-900 sm:truncate flex items-center ">
<div class=" bg-indigo-100 rounded-full p-3 text-indigo-600 mr-4">
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
</svg>
</div>
<h1>
Sign up
</h1>
</div>
</div>
</div>
<div class="w-full p-6 ">
<form action="" method="post" class="max-w-md mx-auto w-full flex flex-col justify-center items-center gap-4 bg-gray-50 rounded-xl p-4 shadow overflow-hidden">
<div class="p-3 text-center">
<h1 class="text-3xl text-gray-900 my-2">
<b>Create your account.</b>
</h1>
<p class="text-sm text-gray-500">Create new admin account for free.</p>
</div>
<div class="w-full ">
<label for="email" class="label required">
Email
</label>
<div>
<input name="email" type="email" class=" input " placeholder="[email protected]" autocomplete="email" maxlength="50" value="<?php echo $email; ?>" required>
<p class="error_text"><?php echo $errors["email"] ? $errors["email"] : ""; ?> </p>
</div>
</div>
<div class="w-full ">
<label for="password" class="label required">
Password
</label>
<div>
<input name="password" type="password" class=" input " placeholder="your new password" autocomplete="new-password" maxlength="50" value="<?php echo $password; ?>" required>
<p class="error_text"><?php echo $errors["password"] ? $errors["password"] : ""; ?> </p>
</div>
</div>
<div class="w-full ">
<div>
<input name="submit" type="submit" class="btn primary" value="Signup">
</div>
</div>
<div class="text-sm text-right">
<a class="font-medium rounded-md text-blue-600 hover:text-blue-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-blue-500" href="/rms/login.php">Already have an account?</a>
</div>
<div class="text-xs text-red-500 "><?php echo $error ? $error : ""; ?></div>
</form>
</div>
<?php include "footer.php"; ?>