SQL UPDATE issues
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' WHERE NameID=$form;");
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
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.
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:
$sql = "SELECT * FROM table WHERE id = '$id'";
echo $sql; // Comment out or delete this line after you have it working
"SET Lastname='".$form."' "
Last edited by legendx; 05-27-2008 at 10:26 AM.
Aww....the NameID was NULL...I hate life, but love you! Thanks for the clear and simple answer!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)