-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
94 lines (81 loc) · 3.11 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
<?php
$showAlert = false;
$showError = false;
if($_SERVER["REQUEST_METHOD"] == "POST"){
include 'partials/_dbconnect.php';
$username = $_POST["username"];
$password = $_POST["password"];
$cpassword = $_POST["cpassword"];
$existSql = "SELECT * from `users` WHERE username ='$username'";
$result = mysqli_query($conn, $existSql);
$numExistRows = mysqli_num_rows($result);
if($numExistRows>0){
$showError = "Username already exists.";
}
else{
if($password == $cpassword){
$sql = "INSERT INTO `users` (`username`, `password`, `dt`) VALUES ('$username', '$password', current_timestamp())";
$result = mysqli_query($conn, $sql);
if($result){
$showAlert = true;
}
}
else{
$showError = "Passwords do not match";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signup</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css" rel="stylesheet" />
</head>
<body>
<?php require './partials/_nav.php'?>
<?php
if($showAlert == true){
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Success!</strong> Your account is now created and you can log in.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
</button>
</div> ';
}
if($showError == true){
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error!</strong> '.$showError.'
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
</button>
</div> ';
}
?>
<div class="container mt-5">
<h1 class="text-center">Signup to our website!</h1>
<form action="/project-saad/signup.php" method="post">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name ="username" aria-describedby="emailHelp">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password">
</div>
<div class="mb-3">
<label for="cpassword" class="form-label">Confirm Password
</label>
<input type="password" class="form-control" id="cpassword" name="cpassword">
<div id="emailHelp" class="form-text">Make sure to type the same password!
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<?php require './partials/_footer.php' ?>
</body>
</html>