Hi, I have a script that calls certain data from tables in my database. I want to be able to delete a specific row from the php page. I have currently added a link in the table that will delete a row when clicked, however, it always deletes the last row and not the one that I want it to delete. Here is the code:
<?php
$con = mysql_connect('localhost', '****', '****');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("****", $con);
$sql="SELECT * from flash";
$result = mysql_query($sql);
echo'
<HTML>
<head>
<title>Bans</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="table.js"></script>
<link rel="stylesheet" type="text/css" href="themes/blue/style.css" />
</head>
<body bgcolor="#cccccc">
';
echo'
<table id="myTable" class="tablesorter">
<script type="text/javascript">
$(document).ready(function() {
$("table").tablesorter({
// sort on the first column and third column, order asc
sortList: [[0,0]]
});
});
</script>
<thead>
<tr>
<th>ID</th>
<th>Moderator</th>
<th>User</th>
<th>Action</th>
<th>Length</th>
<th>Date</th>
<th>Delete</th>
</tr>
</thead>
';
echo'
<tbody>';
if(!isset($cmd))
{
while($row = mysql_fetch_array($result))
{
$id=$row['id'];
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['moderator'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['action'] . "</td>";
echo "<td>" . $row['length'] . " minutes</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td><a href='index.php?cmd=delete&id=$id'>Delete</a></td>";
echo "</tr>";
}
}
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM flash WHERE id=$id";
$result = mysql_query($sql);
echo "<meta http-equiv='refresh' content='0; URL=index.php'>";
}
echo'
</tbody>
</table>
</body>
</HTML>';
?>
Any help would be greatly appreciated. Thanks!