In my code it first shows result of table and then it will delete the data upon submit. But there is issue that wherever I click in delete button I will always deleting last row. It does not delete specific row which I want to delete
$servername = "localhost";
$username = "root";
$password = "1234";
$db = "ptcl";
$con = new mysqli($servername, $username, $password, $db);
end connection
html code
<html>
<body>
<div class="content">
<div class="exchange">
<center>EXCHANGE /NTE</center>>
<center>
<form action="delete.php" name="delete" method="POST">
<table border="1">
<tr><th rowspan="2">EXCHANGE TYPE</th>
<th colspan="9">DESCRIPTION</th>
</tr>
<tr>
<td colspan="2">Retail</td>
<td>DTEs</td>
<td>Retail/Sett</td>
<td>Online</td>
<td>Offline</td>
<td>Total</td>
<td colspan="2">Action</td>
</tr>
form which i want to show first then delete by its id
<?php
global $con;
$query="select * from exchange ";
$result =$con->query($query);
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){?>
<tr>
<td><?php echo $row['exchangetype']?></td>
<td><?php echo $row['retail']?><td>
<td ><?php echo $row['dte']?></td>
<td><?php echo $row['retail_sett']?></td>
<td><?php echo $row['retail']+$row['dte']+$row['retail_sett']?></td>
<td><?php echo $row['offine']?></td>
<td><?php echo $row['retail']+$row['dte']+$row['retail_sett']+$row['offine']?></td>
<td><input type="submit" name="delete" value="Delete"/></td>
<td><input type="hidden" name="eid" value="<?php echo $row['eid']?>" />
</td>
<?php }
?>
</tr>
</table>
</form>
</center>
<?php } else{
echo "No record found";
}
?>
</div>
</div>
php delete code starts
global $con
$eeid = $_POST['eid'];
if (isset($_POST['delete'])) {
$query = "DELETE FROM exchange WHERE eid='$eeid' ";
if ($con->query($query) === true) {
echo "DELETED Data";
} else {
echo "error during deletion" . $con->error;
}
}
It will not delete which I want to delete it delete only last row.