-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer_registration.php
234 lines (222 loc) · 6.82 KB
/
customer_registration.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!-- UI: Prithviraj Narahari, php code: Alexander Martens -->
<head>
<title> CUSTOMER REGISTRATION </title>
</head>
<body>
<?php
session_start();
$user = 'admin1';
$pass = 'Admin1Pass4235!a';
$db = 'cosc471';
try {
$dbConnection = new mysqli('localhost', $user, $pass, $db) or die("Unable to connect");
} catch (mysqli_sql_exception $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$username = "";
$pin = "";
$retype_pin = "";
$firstname = "";
$lastname = "";
$address = "";
$city = "";
$state = "";
$cardType = "";
$cardNumber = "";
$isUser = $_SESSION['isUser'];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST['username'])) {
$username = $_POST['username'];
}
if (!empty($_POST['pin'])) {
$pin = $_POST['pin'];
}
if (!empty($_POST['retype_pin'])) {
$retype_pin = $_POST['retype_pin'];
}
if (!empty($_POST['firstname'])) {
$firstname = $_POST['firstname'];
}
if (!empty($_POST['lastname'])) {
$lastname = $_POST['lastname'];
}
if (!empty($_POST['address'])) {
$address = $_POST['address'];
}
if (!empty($_POST['city'])) {
$city = $_POST['city'];
}
if (!empty($_POST['state'])) {
$state = $_POST['state'];
}
if (!empty($_POST['credit_card'])) {
$cardType = $_POST['credit_card'];
}
if (!empty($_POST['card_number'])) {
$cardNumber = $_POST['card_number'];
}
//if statements to check if fields are valid
if (!preg_match("/^[a-zA-Z ]*$/",$firstname)) {
echo "<script type='text/javascript'>alert('First name must contain only letters.');</script>";
}
if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) {
echo "<script type='text/javascript'>alert('Last name must contain only letters.');</script>";
}
if (!preg_match("/^[a-zA-Z ]*$/",$city)) {
echo "<script type='text/javascript'>alert('City must contain only letters.');</script>";
}
if (!preg_match("/^[a-zA-Z ]*$/",$state)) {
echo "<script type='text/javascript'>alert('State must contain only letters.');</script>";
}
if (!preg_match("/^[0-9]*$/",$cardNumber)) {
echo "<script type='text/javascript'>alert('Credit card number must contain only numbers.');</script>";
}
if (strlen($username) > 20) {
echo "<script type='text/javascript'>alert('Username must be less than 20 characters.');</script>";
}
if (!empty($username) && !empty($pin) && !empty($retype_pin) && !empty($firstname) && !empty($lastname) && !empty($address) && !empty($city) && !empty($state) && !empty($cardType) && !empty($cardNumber)) {
//check if PINs match
if($pin == $retype_pin) {
$sql = "SELECT * FROM customer WHERE username = '$username'";
$result = mysqli_query($dbConnection, $sql);
//check if the unsername already exists
if(mysqli_num_rows($result) > 0) {
echo "<script type='text/javascript'>alert('Username already exists.');</script>";
}
else {
$sql = "INSERT INTO customer (username, pin, fname, lname, custaddress, city, custState, cardType, cardNo) VALUES ('$username', '$pin', '$firstname', '$lastname', '$address', '$city', '$state', '$cardType', '$cardNumber')";
$result = mysqli_query($dbConnection, $sql);
$isUser = true;
//add isUser to session
$_SESSION['isUser'] = $isUser;
$_SESSION['cardType'] = $cardType;
$_SESSION['cardNumber'] = $cardNumber;
$_SESSION['username'] = $username;
echo "<script type='text/javascript'>alert('Registration successful.');</script>";
header("Location: screen2.php");
}
}
else {
echo "<script type='text/javascript'>alert('PINs do not match.');</script>";
}
}
else {
echo "<script type='text/javascript'>alert('All fields are required.');</script>";
}
}
?>
<table align="center" style="border:2px solid blue;">
<form id="register" action="customer_registration.php" method="post">
<tr>
<td align="right">
Username<span style="color:red">*</span>:
</td>
<td align="left" colspan="3">
<input type="text" id="username" name="username" placeholder="Enter your username">
</td>
</tr>
<tr>
<td align="right">
PIN<span style="color:red">*</span>:
</td>
<td align="left">
<input type="password" id="pin" name="pin">
</td>
<td align="right">
Re-type PIN<span style="color:red">*</span>:
</td>
<td align="left">
<input type="password" id="retype_pin" name="retype_pin">
</td>
</tr>
<tr>
<td align="right">
Firstname<span style="color:red">*</span>:
</td>
<td colspan="3" align="left">
<input type="text" id="firstname" name="firstname" placeholder="Enter your firstname">
</td>
</tr>
<tr>
<td align="right">
Lastname<span style="color:red">*</span>:
</td>
<td colspan="3" align="left">
<input type="text" id="lastname" name="lastname" placeholder="Enter your lastname">
</td>
</tr>
<tr>
<td align="right">
Address<span style="color:red">*</span>:
</td>
<td colspan="3" align="left">
<input type="text" id="address" name="address">
</td>
</tr>
<tr>
<td align="right">
City<span style="color:red">*</span>:
</td>
<td colspan="3" align="left">
<input type="text" id="city" name="city">
</td>
</tr>
<tr>
<td align="right">
State<span style="color:red">*</span>:
</td>
<td align="left">
<select id="state" name="state">
<option selected disabled>select a state</option>
<option>MI</option>
<option>CA</option>
<option>TN</option>
</select>
</td>
<td align="right">
Zip<span style="color:red">*</span>:
</td>
<td align="left">
<input type="text" id="zip" name="zip">
</td>
</tr>
<tr>
<td align="right">
Credit Card<span style="color:red">*</span>
</td>
<td align="left">
<select id="credit_card" name="credit_card">
<option selected disabled>select a card type</option>
<option>VISA</option>
<option>MASTER</option>
<option>DISCOVER</option>
</select>
</td>
<td colspan="2" align="left">
<input type="text" id="card_number" name="card_number" placeholder="Credit card number">
</td>
</tr>
<tr>
<td colspan="2" align="right">
Expiration Date<span style="color:red">*</span>:
</td>
<td colspan="2" align="left">
<input type="text" id="expiration" name="expiration" placeholder="MM/YY">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" id="register_submit" name="register_submit" value="Register">
</td>
</form>
<form id="no_registration" action="index.php" method="post">
<td colspan="2" align="center">
<form id="no_registration" action="index.php" method="post">
<input type="submit" id="donotregister" name="donotregister" value="Don't Register">
</td>
</form>
</tr>
</table>
</body>
</HTML>