-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignup.php
More file actions
58 lines (56 loc) · 1.93 KB
/
Signup.php
File metadata and controls
58 lines (56 loc) · 1.93 KB
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
<?php
define('DBSERVER', 'localhost');
define('DBUSERNAME', 'root');
define('DBPASSWORD', '');
define('DBNAME', 'bus');
$db=mysqli_connect(DBSERVER,DBUSERNAME,DBPASSWORD,DBNAME);
if($db===false){
die("Error: connection error.".mysql_connect_error());
}
if(isset($_POST['SignUp'])){
echo "sucess2";
$name =trim($_POST['name']);
$username =trim($_POST['username']);
$password =trim($_POST['password']);
$confirm_password =trim($_POST['confirm_password']);
$password_hash= password_hash($password,PASSWORD_BCRYPT);
if($query = $db->prepare("SELECT * FROM customer where username = ?")){
$error = '';
$query->bind_param('s', $username);
$query->execute();
$query->store_result();
if($query->num_rows>0){
$error='<p class="error">The username is already used!</p>';
}else{
//validate password
if(strlen($password ) <6){
$error='<p class="error">Password should of 6 characters</p>';
}
//validate confrim password
if(empty($confirm_password)){
$error='<p class="error">Please Enter the confrim password</p>';
}else{
if(empty($error)&&($password != $confirm_password)){
$error='<p class="error">Password did not match!</p>';
}
}
if(empty($error)){
echo "success3";
$insertQuery = $db->prepare("INSERT INTO customer VALUES(?,?,?)");
$insertQuery->bind_param("sss",$username,$name,$password_hash);
$result = $insertQuery->execute();
if($result){
header("location:index.html");
}else{
$error='<p class="error">Something went worng</p>';
}
}
}
}
else{
echo "error";
}
$query->close();
$insertQuery->close();
mysqli_close($db);
}