|
| Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more. |
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Posts: n/a
|
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>"; } |
|
|
#2 |
|
Older not wiser
Join Date: Nov 2003
Location: Calgary, AB
Posts: 2,473
Reputation: 205
|
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? |
|
|
|
|
#3 |
|
Posts: n/a
|
I tried that already and it works on phpMyAdmin
|
|
|
#4 |
|
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 7,130
Reputation: 333
|
I assume you have done all the connection stuff for mysql.
__________________
I don't suffer from laziness, I enjoy every minute! Edit your php.ini here http://members.powweb.com/member/cgi...nt/PHPplus.bml |
|
|
|
|
#5 |
|
Posts: n/a
|
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.
|
|
|
#6 |
|
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 7,130
Reputation: 333
|
Try echoing the SQL and testing for any errors.
mysql_query( $sql ) or die( $sql . mysql_error() );
__________________
I don't suffer from laziness, I enjoy every minute! Edit your php.ini here http://members.powweb.com/member/cgi...nt/PHPplus.bml |
|
|
|
|
#7 |
|
Posts: n/a
|
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! |
![]() |
| Thread Tools | Search this Thread |
|
|