|
| 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 |
|
|
#1 |
|
Web Designer
Join Date: Nov 2004
Location: Oklahoma City, Oklahoma
Posts: 743
Reputation: 28
|
I have a form that allows the user to specify which record in the table that they want to delete. When they enter a number, it deletes ALL records in the table. I only want to delete the ID# that the user enters on the form.
Why doesn't this work? PHP Code:
|
|
|
|
|
#2 |
|
Older not wiser
Join Date: Nov 2003
Location: Calgary, AB
Posts: 2,472
Reputation: 205
|
It's likely that your PHP code is not concatenating the SQL command string the way you assume it is. Without your actual code it's hard to tell, but I know I've falled into the trap before where I copy/paste a string command - then forget to insert the concatenate operator on the same string to make it join both lines.
|
|
|
|
|
#3 |
|
Web Designer
Join Date: Nov 2004
Location: Oklahoma City, Oklahoma
Posts: 743
Reputation: 28
|
OK. Here is the form:
HTML Code:
PHP Code:
HTML Code:
HTML Code:
PHP Code:
|
|
|
|
|
#4 |
|
Older not wiser
Join Date: Nov 2003
Location: Calgary, AB
Posts: 2,472
Reputation: 205
|
Well ...
you're making progress. In your first post it was deleting EVERYTHING .. now it's NOTHING. So that just means the record doesn't exist as you expect it to exist with the ID value provided. Echo the $sql statement before executing - do you even have a value for $ID in the SQL statement? |
|
|
|
|
#5 |
|
Join Date: Oct 2002
Location: Dallas
Posts: 2,914
Reputation: 311
|
this is wrong:
"DELETE FROM tablename WHERE id = '$ID"; you have an extra single quote in there. either "DELETE FROM tablename WHERE id = $ID"; or "DELETE FROM tablename WHERE id = '$ID'"; I dunno if there are other problems hiding in there. BTW, for cleaning an integer (which I assume $ID is), you can do this: PHP Code:
PHP Code:
|
|
|
|
|
#6 |
|
Web Designer
Join Date: Nov 2004
Location: Oklahoma City, Oklahoma
Posts: 743
Reputation: 28
|
Thanks guys!
|
|
|
![]() |
| Thread Tools | |
|
|