-
Notifications
You must be signed in to change notification settings - Fork 0
/
regprocess.php
85 lines (39 loc) · 1.89 KB
/
regprocess.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
<?php
if (isset($_POST["submit"])) {
// Database connection in separate file
// include ('config.php');
$servername = "localhost"; //My server
$username = "root";
$password = ""; // No password
$dbname = "Cafedb"; //Name of database
//create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$password = mysqli_real_escape_string($conn, md5($_POST["password"]));
$conpassword = mysqli_real_escape_string($conn, md5($_POST["conpassword"]));
$role = mysqli_real_escape_string($conn, $_POST["role"]);
if (mysqli_num_rows(mysqli_query($conn, "SELECT * FROM register WHERE username='{$username}'")) > 0) {
header("Location:register.php");
echo "<script>alert('{$username} - Username has already been taken.');</script>";
}
else {
if ($password === $conpassword) {
$sql = "INSERT INTO register (username,passwords,roles) VALUES ('{$username}', '{$password}', '{$role}')";
$result = mysqli_query($conn, $sql);
if ($result) {
//echo success then redirect
header("Location:login.php");
echo "<script>alert('Success')</script>";
//if result is successful navigate to dashboard page
}else {
echo "<script>Error: ".$sql.mysqli_error($conn)."</script>";
}
}else {
echo "<script>
alert('Passwords do not match !');
window.location.href='register.php';
</script>";
}
}
}
?>