-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign.php
130 lines (87 loc) · 3.54 KB
/
sign.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
125
126
127
128
129
130
<!--
In signup page we just make a new user or will see that the user already exist
if exists:
we say user already exists with this email
if not:
then we create the new user means store the user data in database
After successfully signed up user automatically moved to login.php
-->
<?php
$user = 0;
$success = 0;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
include 'connect.php';
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "select * from `registration` where username ='$username'";
$result = mysqli_query($con, $sql);
// checks that the user exist in the database or not
if ($result) {
$num = mysqli_num_rows($result);
if ($num > 0) {
$user = 1;
}
// if not exist then it insert user data into database only
else {
$sql = "INSERT INTO `registration` (`username`, `password`) values('$username', '$password')";
$result = mysqli_query($con, $sql);
if ($result) {
$success = 1;
echo "<script>
window.location.href = 'login.php';
</script>";
} else {
echo "error while inserting data";
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Signup Page</title>
</head>
<body>
<!-- if user exist then it will show error message; like in stylish bootstrap -->
<?php
if ($user) {
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Oh no </strong> The user already exists with the same email.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
// if user not exist then it will show success message; like in stylish bootstrap
if ($success) {
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Congratulation </strong> User Successfully signed up.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<div class="container mt-5">
<form action="sign.php" method="post">
<h1 class="mb-5">Signup page</h1>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control " id="exampleInputEmail1" aria-describedby="emailHelp"
placeholder="Enter email" name="username" required>
</div>
<div class="form-group mt-3">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" placeholder="enter Password" name="password" required>
</div>
<button type="submit" class="btn btn-primary w-15 mt-3">signup</button>
</form>
</div>
</body>
</html>