HOW TO DELETE DATA IN DATABASE USING PHP WITH MYSQLI

Hey guys, Today we are learning SQLI DELETE QUERY execute in the database. (How to delete data in the database using PHP with MySQL)

1. HTML Source Code(Index.php)

<table border="1" cellspacing="10">
<tr>
<th>S. N.</th>
<th>Name</th>
<th>Email Id</th>
<th>Action.</th>
</tr>
<?php
$conn=mysqli_connect("localhost", "root", "", "testproject");
$query=mysqli_query($conn, "SELECT * FROM userdetails"); while($rows=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td><a href="delete.php?id=<?php echo $rows['id']; ?>">Delete</a></td>
</tr>
<?php } ?>
</table>

2. PHP Source Code(delete.php)

<?php
$conn=mysqli_connect("localhost", "root", "", "testproject");
$id=$_GET["id"];
$query=mysqli_query($conn, "DELETE FROM userdetails WHERE id='$id'");
if(query==true){
echo"Successfully Deleted";
}
else{
echo"Deleted Failed";
}
?>