-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedituser.php
More file actions
193 lines (163 loc) · 6.32 KB
/
edituser.php
File metadata and controls
193 lines (163 loc) · 6.32 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
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
<?php
session_start();
$nameErr = $emailErr = $genderErr = $addressErr = $icErr = $contactErr = $usernameErr = $passwordErr = "";
$name = $email = $gender = $address = $ic = $contact = $uname = $upassword = "";
$cID;
$oUserName;
$oPassword;
$oName;
$oIC;
$oEmail;
$oPhone;
$oAddress;
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "USE bookstore";
$conn->query($sql);
$sql = "SELECT users.UserName, users.Password, customer.CustomerName, customer.CustomerIC, customer.CustomerEmail, customer.CustomerPhone, customer.CustomerGender, customer.CustomerAddress
FROM users, customer
WHERE users.UserID = customer.UserID AND users.UserID = ".$_SESSION['id']."";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
$oUserName = $row['UserName'];
$oPassword = $row['Password'];
$oName = $row['CustomerName'];
$oIC = $row['CustomerIC'];
$oEmail = $row['CustomerEmail'];
$oPhone = $row['CustomerPhone'];
$oAddress = $row['CustomerAddress'];
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Please enter your name";
}else{
if (!preg_match("/^[a-zA-Z ]*$/", $name)){
$nameErr = "Only letters and white space allowed";
$name = "";
}else{
$name = $_POST['name'];
if (empty($_POST["uname"])) {
$usernameErr = "Please enter your Username";
$uname = "";
}else{
$uname = $_POST['uname'];
if (empty($_POST["upassword"])) {
$passwordErr = "Please enter your Password";
$upassword = "";
}else{
$upassword = $_POST['upassword'];
if (empty($_POST["ic"])){
$icErr = "Please enter your IC number";
}else{
if(!preg_match("/^[0-9 -]*$/", $ic)){
$icErr = "Please enter a valid IC number";
$ic = "";
}else{
$ic = $_POST['ic'];
if (empty($_POST["email"])){
$emailErr = "Please enter your email address";
}else{
if (filter_var($email, FILTER_VALIDATE_EMAIL)){
$emailErr = "Invalid email format";
$email = "";
}else{
$email = $_POST['email'];
if (empty($_POST["contact"])){
$contactErr = "Please enter your phone number";
}else{
if(!preg_match("/^[0-9 -]*$/", $contact)){
$contactErr = "Please enter a valid phone number";
$contact = "";
}else{
$contact = $_POST['contact'];
if (empty($_POST["gender"])){
$genderErr = "* Gender is required!";
$gender = "";
}else{
$gender = $_POST['gender'];
if (empty($_POST["address"])){
$addressErr = "Please enter your address";
$address = "";
}else{
$address = $_POST['address'];
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "USE bookstore";
$conn->query($sql);
$sql = "UPDATE users SET UserName = '".$uname."', Password = '".$upassword."' WHERE UserID = "
.$_SESSION['id']."";
$conn->query($sql);
$sql = "UPDATE customer SET CustomerName = '".$name."', CustomerPhone = '".$contact."',
CustomerIC = '".$ic."', CustomerEmail = '".$email."', CustomerAddress = '".$address."',
CustomerGender = '".$gender."'";
$conn->query($sql);
header("Location:index.php");
}
}
}
}
}
}
}
}
}
}
}
}
}
function test_input($data){
$data = trim($data);
$data = stripcslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<html>
<link rel="stylesheet" href="style.css">
<body>
<header>
<blockquote>
<a href="index.php"><img src="image/logo.png"></a>
</blockquote>
</header>
<blockquote>
<div class="container">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<h1>Edit Profile:</h1>
Full Name:<br><input type="text" name="name" placeholder="<?php echo $oName; ?>">
<span class="error" style="color: red; font-size: 0.8em;"><?php echo $nameErr;?></span><br><br>
User Name:<br><input type="text" name="uname" placeholder="<?php echo $oUserName; ?>">
<span class="error" style="color: red; font-size: 0.8em;"><?php echo $usernameErr;?></span><br><br>
New Password:<br><input type="password" name="upassword" placeholder="<?php echo $oPassword; ?>">
<span class="error" style="color: red; font-size: 0.8em;"><?php echo $passwordErr;?></span><br><br>
IC Number:<br><input type="text" name="ic" placeholder="<?php echo $oIC; ?>">
<span class="error" style="color: red; font-size: 0.8em;"><?php echo $icErr;?></span><br><br>
E-mail:<br><input type="text" name="email" placeholder="<?php echo $oEmail; ?>">
<span class="error" style="color: red; font-size: 0.8em;"><?php echo $emailErr;?></span><br><br>
Mobile Number:<br><input type="text" name="contact" placeholder="<?php echo $oPhone; ?>">
<span class="error" style="color: red; font-size: 0.8em;"><?php echo $contactErr;?></span><br><br>
<label>Gender:</label><br>
<input type="radio" name="gender" <?php if (isset($gender) && $gender == "Male") echo "checked";?> value="Male">Male
<input type="radio" name="gender" <?php if (isset($gender) && $gender == "Female") echo "checked";?> value="Female">Female
<span class="error" style="color: red; font-size: 0.8em;"><?php echo $genderErr;?></span><br><br>
<label>Address:</label><br>
<textarea name="address" cols="50" rows="5" placeholder="<?php echo $oAddress; ?>"></textarea>
<span class="error" style="color: red; font-size: 0.8em;"><?php echo $addressErr;?></span><br><br>
<input class="button" type="submit" name="submitButton" value="Edit">
<input class="button" type="button" name="cancel" value="Cancel" onClick="window.location='index.php';" />
</form>
</div>
</blockquote>
</center>
</body>
</html>