PDA

View Full Version : Cannot Delete Mysql record through php script


j2swift
1-6-05, 01:32 PM
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>";
}

mitchind
1-6-05, 01:40 PM
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?

j2swift
1-6-05, 02:01 PM
I tried that already and it works on phpMyAdmin

HalfaBee
1-6-05, 03:20 PM
I assume you have done all the connection stuff for mysql.

j2swift
1-6-05, 03:25 PM
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.

HalfaBee
1-6-05, 03:28 PM
Try echoing the SQL and testing for any errors.
mysql_query( $sql ) or die( $sql . mysql_error() );

j2swift
1-6-05, 04:16 PM
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!