www.webdeveloper.com
Results 1 to 3 of 3

Thread: SQL UPDATE issues

  1. #1
    Join Date
    May 2008
    Location
    Nebraska
    Posts
    32

    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[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
    Nathan Blazek
    BlazekWebDesign

  2. #2
    Join Date
    Jul 2005
    Posts
    159
    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:

    Code:
    $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:

    Code:
    "SET Lastname='".$form[1]."' "
    Last edited by legendx; 05-27-2008 at 10:26 AM.

  3. #3
    Join Date
    May 2008
    Location
    Nebraska
    Posts
    32
    Aww....the NameID was NULL...I hate life, but love you! Thanks for the clear and simple answer!
    Nathan Blazek
    BlazekWebDesign

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles