First We have to fetch all data and display in table then from user table, we will delete data by clicking on delete button.
Click here to understand flowwe recieve del_id by clicking on delete button in delete.php (follow as in image below).
$dbhost ="localhost";
$dbuser ="root";
$dbpswd ="";
$dbname ="dbdemo";
$dbcon= mysqli_connect($dbhost,$dbuser,$dbpswd,$dbname);
if($dbcon){
//echo "Connected............!!!";
return $dbcon;
exit();
}else{
die("Connection failed ? ? ?". mysqli_error($dbcon));
}
mysqli_close($dbcon);
<?php include("dbcon.php"); //This is database connection file
$error=''; $success='';
if(isset($_GET['del_id'])){
$del_id = $_GET['del_id'];
$sql="DELETE FROM users WHERE id='$del_id'";
$run=mysqli_query($dbcon,$sql);
if($run){
$success = "<div class='alert alert-success text-success text-center alert-dismissible'><button type='button' class='close' data-dismiss='alert'>×</button>The user has been deleted Successfully</div>";
header('location:user-list.php?1='.$success);
}else{
$error ="<div class='alert alert-success text-success text-center alert-dismissible'><button type='button' class='close' data-dismiss='alert'>×</button>The The user has not been deleted </div>";
header('location:user-list.php?0='.$error);
}
}else{
$error = "No data deleted";
}
mysqli_close($dbcon);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,
shrink-to-fit=no">
<title>Codetechinfo</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<nav class="navbar navbar-expand-lg navbar-light bg-primary text-white fixed-top">
<a class="navbar-brand text-white" href="./index.php">Learn PHP </a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link text-white" href="./index.php">Home </a>
</li>
</ul>
</div>
</nav>
<br><br>
<div class="copyright py-4 text-center text-white">
<div class="container "><small>© Copyright 2025 by Saten Chauhan</small> </div>
</div>
</body>
</html>