Wondered if anyone could help, this may be more php side than SQL, im not sure, it involves them both.
I have an SQL querie that is used to delete records from a database, it is as follows:
Code:
DELETE FROM categories WHERE category=$category
The $category is generated from a drop down box (select/option in a HTML form) which is populated by a DISTINCT(category) statement.
Now the only problem I have is that there is a record in the database called 'Plumbing & Heating' and when this record is selected the SQL statement trys to delete all records where the category=Plumbing and not the full Plumbing & Heating.
Anyone else come across this problem and been able to resolve it?
Any non-numeric literal value must be quoted within SQL:
PHP Code:
$query = "DELETE FROM categories WHERE category='$category'";
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
It's best to just get in the habit of quoting all HTML element attribute values, as it is required for properly formatted XML and XHTML.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks