-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpoliceviewupdate.php
206 lines (192 loc) · 6.46 KB
/
policeviewupdate.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
<?php
$login_user="";
if(isset($_GET['q'])) {
$login_user = $_GET['q'];
}
$addressErr = $phoneErr = $specErr = "";
$name = $username = $address = $spec = $gender = $phone = "";
$successMsg = $errorMsg = "";
//DB Connection
$servername= "localhost";
$usernamed = "root";
$passwords = "";
$dbname = "cybercrimedatabase";
$conn = new mysqli($servername, $usernamed, $passwords, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$login_user = test_input($login_user);
$sql = "SELECT * from police where police_id='$login_user'";
$result=$conn->query($sql);
$row=$result->fetch_assoc();
$name=$row["name"];
$username=$row["police_id"];
$address=$row["address"];
$spec=$row["specialization"];
$phone=$row["phone"];
$gender=$row["gender"];
$conn->close();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["address"])) {
$addressErr = "Address is required";
} else {
$address = test_input($_POST["address"]);
}
if (empty($_POST["phone"])) {
$phoneErr = "Phone number is required";
} else {
$phone = test_input($_POST["phone"]);
if (!preg_match("/^[0-9]*$/",$phone)) {
$phoneErr = "Only numbers allowed";
}
}
if(isset($_POST['specialization']) && $_POST['specialization'] == '0') {
$specErr = "Specialization is required";
} else {
$spec = test_input($_POST["specialization"]);
}
}
if (!empty($_POST["address"]) && !empty($_POST["phone"]) && isset($_POST['specialization']) && $_POST['specialization'] != '0' && $phoneErr == "")
{
$conn = new mysqli($servername, $usernamed, $passwords, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE police SET address = '$address', phone = '$phone', specialization = '$spec' WHERE police_id = '$login_user'";
if ($conn->query($sql) === TRUE) {
$successMsg = "Update Successful. Click on BACK button.";
}
else {
$errorMsg = "Update Failed due to some Internal Error!!! Please try again.";
}
$conn->close();
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Cyber Crime Records Management System</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.error
{
color: #FF0000;
}
.success
{
color: #008000;
}
*{
padding: 0;
margin: 0;
text-align: center;
}
header {
height: 90px;
background-color: black;
font-family: inherit;
color: wheat;
font-size: 20px;
text-align: center;
}
h2 {
padding: 20px;
font-size: 50px;
}
table {
height:200px;
width:600px;
color:gray;
font:white;
text-align: center;
box-sizing: border-box;
}
form {
display: inline-block;
padding: 25px;
margin: 100px 0;
}
</style>
</head>
<body id="mk">
<header>
<h1>
CYBER CRIME RECORDS MANAGEMENT SYSTEM
</h1>
</header>
<h2 >
View and Update My Details
</h2>
<div>
<form method="post" action="#">
<table border="6.0">
<tr>
<td > Username/Police ID:</td>
<td> <?php echo $username; ?></td>
</tr>
<tr>
<td > Name:</td>
<td> <?php echo $name; ?></td>
</tr>
<tr>
<td > Gender:</td>
<td> <?php echo $gender; ?></td>
</tr>
<tr>
<td > Address:</td>
<td >
<input type="text" name="address" value="<?php echo $address; ?>">
<span class="error">* <?php echo $addressErr;?></span>
</td>
</tr>
<tr>
<td > Phone No:</td>
<td >
<input type="text" name="phone" value="<?php echo $phone; ?>">
<span class="error">* <?php echo $phoneErr;?></span>
</td>
</tr>
<tr>
<td> Specialization: </td>
<td> <?php echo $spec; ?>
<br>
<select name="specialization">
<option value="0">Please Select</option>
<option>Bank Account Fraud</option>
<option>Cyberbullying</option>
<option>Child Pornography</option>
<option>Identity Theft</option>
<option>Social Media Crime</option>
<option>Hacking and Viruses</option>
<option>E-Commerce Scam</option>
<option>Email or Phone Call Scam</option>
</select>
<span class="error">* <?php echo $specErr;?></span>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Update">
</td>
<td>
<input type="button" value="Back" onclick="location.href='policewelcome.php?q=<?php echo $login_user; ?>';" style="width:65px;">
<br>
<span class="success"><?php echo $successMsg;?></span>
<span class="error"><?php echo $errorMsg;?></span>
</td>
</tr>
</table>
</form>
</div>
<div class="footer" style="position: fixed; left: 0; bottom: 0; width: 100%; background-color: gray; color: white; text-align: center;">
<p>©2021 Cyber Crime Records Management System</p>
</div>
</body>
</html>