In my data base , i want to delete records however the username ‘admin’ cannot be deleted. When i try to delete ‘admin’ i get error message " Admin cannot be deleted, how ever I am unable to delete non admin , Appreciate your help
code follows:-
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Registration</title>
6 <link rel="stylesheet" href="styles.css" />
7 </head>
8 <body>
9 <center> <table border='0' cellpadding='10' cellspacing='0' style=\"border: 2px solid #07ACE 1;
10 border-radius: 1em 1em 1em 1em;>
11
12 <table border='1'>
13 <td id=tdfrow>User ID</td>
14 <td id=tdrow>Username</td>
15 <td id=tdrow>Email</td>
16 <td id=tdrow>Date Time</td>
17 <td id=tdlrow> Action</td>
18
19 <?php
20 require ('header_new.php') ;
21 require('config.php');
22 echo"<h3>Display Users</h3>";
23
24 $sql_data = "SELECT * FROM login";
25 $result_data=mysqli_query($conn, $sql_data);
26
27 if (!$result_data) {
28 die ('Could not get data:' . mysqli_error());
29 }
30
31 while($row_data = mysqli_fetch_assoc($result_data)) {
32 echo "<tr>";
33 echo "<td>" . $row_data['id'] . "</td>";
34 echo "<td>" . $row_data['username'] . "</td>";
35 echo "<td>" . $row_data['email'] . "</td>";
36 echo "<td>" . $row_data['dtime'] . "</td>";
37 echo "<td><form class='new' action= '' method='POST'><input type='hidden' name='id' val ue=" .$row_data['id']. "><input type='submit' class='cancelbtn1' name='delete' value='DELET E''></form></td>";
38 }
39 if(isset($_POST['delete'])) {
40 $id=$_POST['id'];
41 echo "$id";
42 $query = "SELECT * FROM login WHERE id='$id'";
43 $result_data = mysqli_query($conn,$query);
44 while($row_data=mysqli_fetch_assoc($result_data )) {
45 echo $row_data['username'];
46
47 if($row_data['username']=='admin') {
48 echo "Admin cannot be deleted";
49 } else {
50 $query = "DELETE FROM login WHERE id='$id'";
51 header("Location:register_view.php");
52
53 }
54 }
55 }
56
57 ?>
58 </body>
59 </html>