-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.php
46 lines (39 loc) · 1.31 KB
/
server.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
<?php
$name = "";
$email_2 = "";
$mobile_no_2 = "";
$errors = array();
// connect to the database
$db = mysqli_connect('localhost','root', '','registration');
// if the signup button is clicked
if (isset($_POST['signup'])) {
$name = mysql_real_escape_string($_POST['name']);
$email_2 = mysql_real_escape_string($_POST['email_2']);
$mobile_no_2 = mysql_real_escape_string($_POST['mobile_no_2']);
$password_2 = mysql_real_escape_string($_POST['password_2']);
$password_3 = mysql_real_escape_string($_POST['password_3']);
// ensure that form fields are filled properly
if (empty($name)) {
array_push($errors, "Name is required");
}
if (empty($email_2)) {
array_push($errors, "Email is required");
}
if (empty($mobile_no_2)) {
array_push($errors, "Mobile no. is reqiured");
}
if (empty($password_1)){
array_push($errors, "Password is required");
}
if($password_2 != $password_3) {
array_push($errors, "Password do not match");
}
// if there are no errorss, save user to database
if (count($errors) == 0) {
$password = md5($password_2); //encrypt password before storing in database (security)
$sql = "INSERT INTO users (name, email, mobil number, password)
VALUES ('$name', '$email_2', '$mobile_no_2', '$password')";
mysqli_query($db, $sql);
}
}
?>