Posted by J.O. Aho on 04/23/06 21:30
Mark D. Smith wrote:
> Hi
>
> i can INSERT and UPDATE but DELETE is not working
>
> $sql = "DELETE FROM table WHERE ID='$ID'";
> $sql_result = mysql_query($sql,$connection) or die ("Couldn't execute Delete
> of row $ID.");
>
> $ID is the primary key and i want to delete the entire row based on the
> users selection.
$sql="DELETE FROM table WHERE ID='$ID'";
if(!($del_res=mysql_query($sql))) {
$sql="SELECT ID FROM table WHERE ID='$ID'";
if($sel_res=mysql_query($sql)) {
if(mysql_num_rows($sel_res)) {
echo "Couldn't delete $ID\n";
} else {
echo "False positive result, there is no $ID in the table\n";
}
} else {
echo "There aren't any $ID in the table\n";
}
} else {
if($rows=mysql_affected_rows($del_res)) {
echo "Number of entries deleted: $rows\n";
} else {
echo "There wasn't anything to delete\n";
}
}
This should give you a better understanding why the delete failed.
//Aho
[Back to original message]
|