Hi all, I'm just learning how to delete records from a test table but I'm having some problems with it. I'm not sure exactly but it looks like it is deleting the last row from the table no matter which record is clicked on. It also appears that it is deleting all records after the record clicked on but excluding that one. If that makes sense!. Anyway here is the code I got from a tutorial on the net;
<?php
$dbhost='localhost';
$dbusername='root';
$dbname = 'test';
mysql_connect ($dbhost, $dbusername);
mysql_select_db($dbname) or die('Cannot select database');
$query = "SELECT * FROM test4";
$result = mysql_query($query) or die('Error, query failed');
if(!isset($cmd)){
while($row = mysql_fetch_array($result)) {
$id = $row["id"];
echo "<strong> tom</strong>: {$row['Tom']}</p>";
echo "<strong> id</strong>: {$row['id']}</p>";
echo "<p><a href='?cmd=delete&id=$id'>delete</a></p>" ;
}
}
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM test4 WHERE id=$id";
$result = mysql_query($sql);
}
?>
Any help is appreciated.