Click to See Complete Forum and Search --> : SQL UPDATE issues


ncblazek
05-27-2008, 10:28 AM
Hello everyone! I am trying to get my SQL update command to work, but nothing updates and I get a SQL syntax reported back.

Here is my table creation query:

mysql_query("CREATE TABLE Name ( NameID INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY, Lastname VARCHAR(50), Firstname VARCHAR(25), Title VARCHAR(10), E_ContactYN VARCHAR(3), EmailID INT(10));");

here is my update query that is having problems, any ideas?

mysql_query("UPDATE `Name` SET Lastname='$form[1]' WHERE NameID=$form[17];");


The SQL Error is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

legendx
05-27-2008, 11:23 AM
I assume you're using PHP with the looks of those variables and functions. Instead of writing the query directly inside the mysql_query() function, write it to a variable and print it before you fire off the query. This will help you debug these kinds of things much faster and more effectively.

Something Like:


$sql = "SELECT * FROM table WHERE id = '$id'";
echo $sql; // Comment out or delete this line after you have it working
mysql_query($sql);


I have a hunch one of your variables is null. At second glance.. I'm pretty sure you can't have array variables inside quotes like that. You need something like:


"SET Lastname='".$form[1]."' "

ncblazek
05-27-2008, 11:32 AM
Aww....the NameID was NULL...I hate life, but love you! Thanks for the clear and simple answer!