-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
102 lines (78 loc) · 3.32 KB
/
register.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
<?php
include("./temp/connection.php") ;
include("./temp/header.php");
// go to home page if user is log
session_start();
if($_SESSION){
header("location: index.php");
}
$error = ["fname" => "" ,"lname" => "" ,"email" => "" ,"pass1" => "" ,"pass2" => "" ];
$fname = $lname = $email = $pass1 = $pass2 = "";
if(isset($_POST["submit"])){
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$email = $_POST["email"];
$pass1 = $_POST["pass1"];
$pass2 = $_POST["pass2"];
// check if a user exist
$sqlGet = "SELECT * FROM userstable WHERE email = '$email'";
$result = mysqli_query($connection,$sqlGet);
$datas = mysqli_fetch_all($result,MYSQLI_ASSOC);
if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
$error["email"] = "Email address is invalid";
}elseif(mysqli_num_rows($result) > 0){
$error["email"] = "User Already Exist";
}
// check if input is Empty
if(empty($fname)){
$error["fname"] = "First Name is empty";
}
if(empty($lname)){
$error["lname"] = "Last Name is empty";
}
if(empty($pass1)){
$error["pass1"] = "Password is empty";
}elseif(strlen($pass1) <= 5){
$error["pass1"] = "Password must be greater than 6";
}
if($pass1 != $pass2){
$error["pass2"] = "Password does not match";
}
if(array_filter($error)){
// nothing happen
}else{
// insert data into the table
$sql = "INSERT INTO userstable(firstname , lastname , email , password) VALUE('$fname','$lname','$email','$pass1')";
if(mysqli_query($connection ,$sql)){
header("location: login.php");
}else{
echo "bad" . mysqli_error($connection);
}
}
}
?>
<div class="reg-page">
<form action="register.php" method="POST">
<h1>Register an account</h1>
<p>Already have an account <a href="login.php">Login</a></p>
<label for="">First Name</label>
<input type="text" name="fname" id="" placeholder="Enter your first name" value="<?php echo $fname ?>">
<span class="error"><?php echo $error["fname"] ?></span>
<label for="">Last Name</label>
<input type="text" name="lname" id="" placeholder="Enter your last name" value="<?php echo $lname ?>">
<span class="error"><?php echo $error["lname"] ?></span>
<label for="">Email</label>
<input type="email" name="email" id="" placeholder="Enter your email address" value="<?php echo $email ?>">
<span class="error"><?php echo $error["email"] ?></span>
<label for="">Password</label>
<input type="password" name="pass1" id="" placeholder="Enter your password" value="<?php echo $pass1 ?>">
<span class="error"><?php echo $error["pass1"] ?></span>
<label for="">Confirm Password</label>
<input type="password" name="pass2" id="" placeholder="confirm your password" value="<?php echo $pass2 ?>">
<span class="error"><?php echo $error["pass2"] ?></span>
<button class="btn btn-dark" name="submit">Submit Form</button>
</form>
</div>
<?php
include("./temp/footer.php") ;
?>