-
Notifications
You must be signed in to change notification settings - Fork 0
/
register_submit.php
85 lines (70 loc) · 2.56 KB
/
register_submit.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
//form validation and inserting of data to database
if($_SERVER["REQUEST_METHOD"] === "POST") {
//test_input for email
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
//get filename of uploaded photo
$photo = basename($_FILES["fileToUpload"]["name"]) ?? null;
if(strlen(trim( $first_name) ) < 1 ){
$error_message .= 'First name is required.<br />';
$error = 1;
}
if(strlen(trim( $last_name) ) < 1 ){
$error_message .= 'Last name is required.<br />';
$error = 1;
}
if(strlen(trim( $user_name) ) < 1 ){
$error_message .= 'User name is required.<br />';
$error = 1;
}
if(strlen(trim( $email) ) < 1 ){
$error_message .= 'Email is required.<br />';
$error = 1;
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message = "Invalid email format";
$error = 1;
}
}
if(strlen(trim( $password) ) < 1 ){
$error_message .= 'Password is required.<br />';
$error = 1;
}
if(strlen(trim( $confirm_password) ) < 1 ){
$error_message .= 'Please confirm your password.<br />';
$error = 1;
}
//check if password and confirm_password is the same
if( $password != $confirm_password ){
$error_message .= 'Password did not match, please try again.';
$error = 1;
$password_error = 1;
}
//if there is no error, proceed to inserting data to database
if(empty($error_message)) {
//insert data to database
$data = "INSERT INTO user_info (first_name, last_name, birth_date, gender, address, user_name, email, password, photo, short_bio)VALUES ( :first_name, :last_name , :birth_date , :gender , :address , :user_name , :email, :password , :photo, :short_bio )";
if($statement = $pdo->prepare($data)){
$statement->bindValue(':first_name', $first_name);
$statement->bindValue(':last_name', $last_name);
$statement->bindValue(':birth_date', $birth_date);
$statement->bindValue(':gender', $gender);
$statement->bindValue(':address', $address);
$statement->bindValue(':user_name', $user_name);
$statement->bindValue(':email', $email);
$statement->bindValue(':password', md5($password));
$statement->bindValue(':photo', $photo);
$statement->bindValue(':short_bio', $short_bio);
$statement->execute();
header("Location: login_screen.php");
}
}
}
?>