-
Notifications
You must be signed in to change notification settings - Fork 0
/
register_form.php
62 lines (54 loc) · 1.93 KB
/
register_form.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
<?php
@include 'config.php';
if(isset($_POST['submit'])){
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$pass = $_POST['password'];
$cpass = $_POST['cpassword'];
$user_type = 'waiting';
$select = "SELECT * FROM user_form WHERE email = '$email'";
$result = mysqli_query($conn, $select);
if(mysqli_num_rows($result) > 0){
$error[] = 'User already exists!';
} else {
if($pass != $cpass){
$error[] = 'Passwords do not match!';
} else {
$hashed_pass = md5($pass);
$insert = "INSERT INTO user_form(name, email, password, user_type) VALUES('$name','$email','$hashed_pass','$user_type')";
mysqli_query($conn, $insert);
header('location:login_form.php');
}
}
}
?>
<!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>Register Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="form-container">
<form action="" method="post">
<h3>Register Now</h3>
<?php
if(isset($error)){
foreach($error as $error){
echo '<span class="error-msg">'.$error.'</span>';
}
}
?>
<input type="text" name="name" required placeholder="Enter your name">
<input type="email" name="email" required placeholder="Enter your email">
<input type="password" name="password" required placeholder="Enter your password">
<input type="password" name="cpassword" required placeholder="Confirm your password">
<input type="submit" name="submit" value="Register Now" class="form-btn">
<p>Already have an account? <a href="login_form.php">Login now</a></p>
</form>
</div>
</body>
</html>