-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertuser.php
84 lines (62 loc) · 2.13 KB
/
insertuser.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
<?php
require_once 'sqlconnection.php';
require_once 'authentication.inc';
$username = $_POST["username"];
$fullname = $_POST["fullname"];
$pass1 = $_POST["password"];
$pass2 = $_POST["password_confirm"];
$email1 = $_POST["email"];
$email2 = $_POST["email_confirm"];
$city = $_POST["city"];
session_start();
$_SESSION["UsernameTaken"]= false;
$_SESSION["Emailexists"]= false;
$_SESSION["PasswordMatch"]= true;
$_SESSION["EmailMatch"]= true;
//check if username already exists
$usernamequery = "SELECT username FROM user WHERE username = '{$username}'";
// Execute the query
$result = $conn->query($usernamequery);
//showerror();
// exactly one row? then user
if ($result->num_rows == 1)
$_SESSION["UsernameTaken"] = true;
//check if email exist
$emailquery = "SELECT email FROM user WHERE email = '{$email1}'";
// Execute the query
$result = $conn->query($emailquery);
//showerror();
// exactly one row? then user
if ($result->num_rows == 1)
$_SESSION["Emailexists"] = true;
//check for passwork match
if($pass1!== $pass2)
$_SESSION["PasswordMatch"] = false;
//check for email match
if($email1!=$email2)
$_SESSION["EmailMatch"] = false;
// if username exists ask to try another one
// if password confirm doesn't match- ask to re-enter
// if email confirm doesn't match- ask to re-enter
// if email exists, let user know and ask them to login with it
// continue to insert only if all above is not an issue
if ($_SESSION["UsernameTaken"]== false &&
$_SESSION["Emailexists"]== false &&
$_SESSION["PasswordMatch"]== true &&
$_SESSION["EmailMatch"]== true){
$insertNewUser = "Insert into user
(username,uname,email,city,password) Values ('{$username}','{$fullname}','{$email1}','{$city}','{$pass1}')";
//reset session
$_SESSION["UsernameTaken"]= false;
$_SESSION["Emailexists"]= false;
$_SESSION["PasswordMatch"]= true;
$_SESSION["EmailMatch"]= true;
$_SESSION["logingmsg"] = "sign up complete!, please login";
$conn->query($insertNewUser);
//showerror();
header("Location: index.php");
}else{
// go back
header("Location: signup.php");
}
?>