I know this question has been asked too many times but I've searched and found nothing to solve my problem. In the table I have 4 columns: id
(auto increment and primary key), type
, quantity
and date
. The problem is when I press delete link it won't delete specific row I want and please forget about code injection, this is meant to be a sample program. Thanks.
The code for a table is like this:
<div id="content" align="center">
<table border="1">
<tr>
<td>Item</td>
<td>Quantity</td>
<td>Date</td>
<td></td>
</tr>
<?php
include("connect.php");
$query=("SELECT * FROM purchase");
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['1'];?></td>
<td><?php echo $row['2'];?></td>
<td><?php echo $row['3'];?></td>
<td><a href="delete.php">Delete</a></td>
</tr>
<?php
}
?>
</table>
</div>
And the delete function:
<?php
include("connect.php");
$host="localhost";
$user="root";
$pass="";
$db_name="proyek";
$tbl_name="purchase";
mysql_connect("$host", "$user", "$pass")or die("Cannot connect to SQL.");
mysql_select_db('$db_name');
$query=("SELECT * FROM purchase");
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$id=$row[0];
mysql_query("DELETE from purchase WHERE id='$id'");
header("location:purchasehistoryadmin.php");
?>