mysql error You have an error in your SQL syntax near.....

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

mysql error You have an error in your SQL syntax near.....

Post by fariquzeli »

I keep getting this error that I have an error in my SQL syntax near line 1:

You have an error in your SQL syntax near '* FROM products WHERE id = 41' at line 1


here's the code around that region:

Code: Select all

<?php
if (isset($_POST['delete_yes'])) {
$_POST['id'] = $id;
$delete_query = "DELETE * FROM products WHERE id = $id";
$do_delete_query = mysql_query($delete_query) or die(mysql_error()); 
echo ("Successfully deleted product.<BR><BR>");
echo ("<a href='index.php'>Return to Product DB Admin.</a>");
}
?>
the id is taken from a hidden field within a form. That hidden field gets its value from the get variable in the URL. Now I thought you could delete an entire MYSQL row at once and this was the syntax I thought you used, but I guess I'm wrong?

If anyone knows what may be causing this please respond ASAP
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

remove

Post by phpScott »

remove the * and you will be happy.
:D
phpScott
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Although phpScott gave the answer it is worthwhile to mention that for checking syntax, mysql.com is always useful:
http://www.mysql.com/doc/en/DELETE.html

Mac
Post Reply