-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.php
130 lines (107 loc) · 4.7 KB
/
insert.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
include 'sanitizeString.php';
$con=mysqli_connect("localhost","root","","library");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$username = sanitize_string($_POST['username'],2,44);
if ($username == FALSE)
{
echo '<script type="text/javascript"> alert(\'your username is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$password = sanitize_string($_POST['password'],2,44);
if ($password == FALSE)
{
echo '<script type="text/javascript"> alert(\'your password is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$firstname = sanitize_string($_POST['firstname'],2,44);
if ($firstname == FALSE)
{
echo '<script type="text/javascript"> alert(\'your first name is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$surname = sanitize_string($_POST['surname'],2,44);
if ($surname == FALSE)
{
echo '<script type="text/javascript"> alert(\'your surname is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$addressl1 = sanitize_string($_POST['addressl1'],2,100);
if ($addressl1 == FALSE)
{
echo '<script type="text/javascript"> alert(\'your address line 1 is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$addressl2 = sanitize_string($_POST['addressl2'],2,100);
if ($addressl2 == FALSE)
{
echo '<script type="text/javascript"> alert(\'your address line 2 is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$city = sanitize_string($_POST['city'],2,32);
if ($city == FALSE)
{
echo '<script type="text/javascript"> alert(\'your city is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$telephone = sanitize_string($_POST['telephone'],7,14);
if ($telephone == FALSE)
{
echo '<script type="text/javascript"> alert(\'your telephone number is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$mobile = sanitize_string($_POST['mobile'],10,14);
if ($mobile == FALSE)
{
echo '<script type="text/javascript"> alert(\'your mobile number is invalid, try again\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
die();
}
$check_user="SELECT * FROM user WHERE '$username' = username";
$result = mysqli_query($con,$check_user) or die ("Error in query: $query " . mysql_error());
$row = mysqli_fetch_array($result);
$num_results = mysqli_num_rows($result);
if ($num_results > 0 )
{
echo '<script type="text/javascript"> alert(\'This username has already been taken, please choose another\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
exit;
}
$check_user="SELECT * FROM user WHERE '$firstname' = firstname AND '$surname' = surname AND '$addressl1' = addressl1";
$result = mysqli_query($con,$check_user) or die ("Error in query: $query " . mysql_error());
$row = mysqli_fetch_array($result);
$num_results = mysqli_num_rows($result);
if ($num_results > 0 )
{
echo '<script type="text/javascript"> alert(\'A user with these details has already been registered, if you cannot remember your password please contact us for assistance\'); </script>';
echo '<script type="text/javascript">location.href = \'register.php\';</script>';
exit;
}
$sql="INSERT INTO User (username, password, firstname, surname, addressl1, addressl2, city, telephone, mobile)
VALUES
('$username','$password','$firstname','$surname','$addressl1','$addressl2','$city','$telephone','$mobile')";
mysqli_query($con,$sql)) or die('Error: ' . mysqli_error($con));
echo '<script type="text/javascript">location.href = \'index.php\';</script>';
echo '<script type="text/javascript"> alert(\'your account has been sucessfully registered\'); </script>';
mysqli_close($con);
?>
</body>
</html>