Follow the Step:
Step 1:
Select the host
Step2: Connect to the database
Step3: Fetch the Data using mysqli_fetch_array() function .
Step4:Add <a href ='index.php?id=$id'> it.
Step2: Connect to the database
Step3: Fetch the Data using mysqli_fetch_array() function .
Step4:Add <a href ='index.php?id=$id'> it.
Step5:Check
id and execute delete query
My Database Name is registration and table name is user.
Index.php
<body>
<?php
$username = "root";
$password = "";
$hostname =
"localhost";
$database_name='registration';
$dbhandle =
mysqli_connect($hostname ,$username ,$password ,$database_name)
or die("Unable to connect
to MySQL");
$query="select *from
user";
$abc= mysqli_query($dbhandle,$query);
?>
<center>
<table border="1"
cellspacing="1" cellpading>
<tr>
<td>Id</td>
<tr>
<td>Id</td>
<td>Name</td>
<td>Password</td>
<td>Email</td>
<td>Password</td>
<td>Email</td>
<td>delete</td>
</tr>
<?php
<?php
while ($row = mysqli_fetch_array($abc))
{
$id= $row['id'];
echo "<tr align='center'>";
echo"<td><font
color='black'>" .$row['id']."</font></td>";
echo"<td><font
color='black'>" .$row['name']."</font></td>";
echo"<td><font
color='black'>". $row['password'].
"</font></td>";
echo"<td><font
color='black'>". $row['email']. "</font></td>";
echo"<td> <a href
='index.php?id=$id'><center>Delete</center></a>";
echo "</tr>";
}
if(isset($_GET['id']))
{
$delete_id=$_GET['id'];
$query="DELETE FROM user
WHERE id='".$delete_id."';
$message=mysqli_query($dbhandle,$query);
if($message)
{
echo"Successfully Deleted";
} else
{
echo"Something Going Wrong";
}
}
?>
</table>
</center>
</body>
Output will be
After Delete id=4
Output will be . Refresh the page
No comments:
Post a Comment