-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
87 lines (76 loc) · 3.33 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
<?php
include('./php/connect_DB.php');
// session_start();
// check if the user is logged in
if (isset($_COOKIE['login_user_id'])) {
header('location: index.php');
}
if (isset($_POST['signup'])){
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$email = $_POST['email'];
$password = $_POST['password'];
// Hash the password using bcrypt
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Use prepared statements
$query = "INSERT INTO users (fname, lname, email, password) VALUES (?, ?, ?, ?)";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, "ssss", $first_name, $last_name, $email, $hashed_password);
mysqli_stmt_execute($stmt);
// Redirect the user to the login page
header("location: login.php");
exit();
}
?>
<!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">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
<link rel="stylesheet" href="../Blog/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="../Blog/css/style.css?"/>
<title>Sign up</title>
</head>
<body>
<?php include("./php/header.php");?>
<br><br>
<div class="container my-5" style="max-width: 400px;">
<div class="errorMessage"></div>
<div class="h3 text-center mb-1">Sign Up Now</div>
<form action="<?php $_SERVER['PHP_SELF']; ?>" class="card p-3 mt-4" id="signup-form" method="POST">
<div class="mb-3 form-floating">
<input type="text" class="form-control" id="fname" aria-describedby="emailHelp" placeholder="First Name" name="fname" required>
<label for="fname" class="form-label">First Name</label>
</div>
<div class="mb-3 form-floating">
<input type="text" class="form-control" id="lname" aria-describedby="emailHelp" placeholder="Last Name" name="lname" required>
<label for="lname" class="form-label">Last Name</label>
</div>
<div class="mb-3 form-floating">
<input type="email" class="form-control" id="email" aria-describedby="emailHelp" placeholder="Email address" name="email">
<label for="email" class="form-label">Email address</label>
</div>
<div class="mb-3 form-floating">
<input type="password" class="form-control" id="password" placeholder="Password" style="position: relative;" name="password">
<i class="fa-solid fa-eye eye"></i>
<label for="password" class="form-label">Password</label>
</div>
<div class="mb-3 form-floating">
<input type="password" class="form-control" id="cpassword" placeholder="Confirm Password" style="position: relative;" name="cpassword">
<i class="fa-solid fa-eye eye"></i>
<label for="cpassword" class="form-label">Confirm Password</label>
</div>
<div class="mb-3 ms-2">
<div id="emailHelp" class="form-text">Already have an account? <a href="./login.php">Login</a></div>
</div>
<button type="submit" name="signup" class="btn btn-success">sign up</button>
</form>
</div>
<?php include("./php/footer.php");?>
<script src="../Blog/js/jquery.min.js"></script>
<script src="../Blog/js/script.js"></script>
<script src="../Blog/js/bootstrap.min.js"></script>
</body>
</html>