-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.inc.php
More file actions
59 lines (47 loc) · 1.51 KB
/
Copy pathsignup.inc.php
File metadata and controls
59 lines (47 loc) · 1.51 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
59
<?php
#first if
if (isset($_POST['submit'])) {
include 'dbh.inc.php';
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
$type = $_POST['type'];
//Error handelers
if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
header("Location: ../signupform.php?signup=empty");
exit();
} else{
//Check if input character are valid
if (!preg_match("/^[a-zA-Z]*$/" , $first) || !preg_match("/^[a-zA-Z]*$/" , $last) ) {
header("Location: ../signupform.php?signup=invalid");
exit();
} else{
// Check if email is valid
if (!filter_var( $email , FILTER_VALIDATE_EMAIL )) {
header("Location: ../signupform.php?signup=email");
exit();
} else {
$sql = "SELECT * FROM users WHERE user_uid='$uid'";
$result = mysqli_query($conn , $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
header("Location: ../signupform.php?signup=usertaken");
exit();
} /*forth else*/ else {
//Hashing the password
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
//Inser the user into the database
$sql = "INSERT INTO users (user_first , user_last , user_email , user_uid , user_pwd, user_type) VALUES ('$first','$last','$email','$uid','$hashedPwd', '$type');";
mysqli_query($conn , $sql);
header("Location: ../signupform.php?signup=success");
exit();
}
}
}
}
}else {
header("Location: ../signupform.php");
exit();
}