I'm writing some simple code to add and delete property info to a DB. The adding part works fine, I just can't seem to delete rows from my table.
My DB user account has read and write permissions, so I guess its the code.
I'm basically telling the page to connect to the DB, read whats there and add a link to delete that row (from the variable ID).
It seems to work fine, it is just not deleting the row when the link is clicked.
<?php
include 'connect.php';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$data = mysql_query("SELECT * FROM Property")
or die(mysql_error());
Print "<table border=\"0\" cellpadding=\"3\">";
while($info = mysql_fetch_array( $data ))
{
// Display contents of DB
Print "<tr>";
Print "<th>Property Name:</th> <td>".$info['PropertyName']."</td> ";
Print "<th>Detail 1:</th> <td>".$info['Detail1']."</td> ";
Print "<th>Detail 2:</th> <td>".$info['Detail2']."</td> ";
Print "<th>Detail 3:</th> <td>".$info['Detail3']."</td> ";
Print "<th>Address:</th> <td>".$info['Address']."</td> ";
Print "<th>Map:</th> <td>".$info['Map']."</td> ";
Print "<th>Image 1:</th> <td><img src=\"".$info['Img1']."\" width=\"50\" height=\"50\"></td> ";
Print "<th>Image 2:</th> <td><img src=\"".$info['Img2']."\" width=\"50\" height=\"50\"></td> ";
Print "<th>Image 3:</th> <td><img src=\"".$info['Img3']."\" width=\"50\" height=\"50\"></td> ";
Print "<th>Image 4:</th> <td><img src=\"".$info['Img4']."\" width=\"50\" height=\"50\"></td> ";
echo "<th>Remove:</th> <td><a href='addremoveproperty.php?cmd=delete&ID=".$info['ID']."'>Delete</a></td></tr>";
}
Print "</table>";
?>
<?
if($cmd=="delete")
{
$data = mysql_query("DELETE FROM Property WHERE ID=$ID")
or die(mysql_error());
print "<strong>Row deleted!</strong>";
}
?>
Any ideas?
Thanks!

New Topic/Question
Reply




MultiQuote





|