View Full Version : Cannot Delete Mysql record through php script
Im having trouble deleting records through php.
I don't know if it could be a setting in my php.ini file or what.
Below is the script with what im trying to do
mysql_query("DELETE FROM `table` WHERE `no` = '58' LIMIT 1");
if (mysql_affected_rows() == 1){
echo "<p>You have successfully deleted this item!</p>";
} else {
echo "<p>Error! Item not deleted</p>";
}
I'd try your SQL syntax first in phpMyAdmin to see if it works there first. Otherwise you're not sure if its a php problem or SQL syntax.
I'm not sure but I think it might be the LIMIT clause you have on the end.
Doesn't it need a start number and number of records?
I tried that already and it works on phpMyAdmin
I assume you have done all the connection stuff for mysql.
Yes I have, it's weird i have used the same setup for my other queries on my site and they all work fine. I am just having trouble with this DELETE query. What im trying to do exactly is to provide a link in a table that when clicked will pass the value of the row to be deleted to a delete.php page that receives this value and runs the query to delete the specified row.
Try echoing the SQL and testing for any errors.
mysql_query( $sql ) or die( $sql . mysql_error() );
Hey thanks a lot guys !
I found that the problem was with the access granted to the user defined in my sqcript.
When I did :
mysql_query($query) or die( $sql . mysql_error() );
I learned that the user did not have access granted to delete.
Again thanks a million!
vBulletin v3.6.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.