SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: syntax error

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking syntax error

    hi people i was wondering if someone could spot where my code is incorrect, because i cant seem to find the error. heres the error mesage. thanks in advance to all.

    INSERT INTO admin SET admin_username='12' admin_password='c20ad4d76fe97759aa27a0c99bff6710' admin_firstname='12' admin_lastname='12' 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 'admin_password='c20ad4d76fe97759aa27a0c99bff6710' admin_first
    here the code.

    PHP Code:
    $query "INSERT INTO admin SET 
    admin_username='" 
    $_POST['admin_username']. "'
    admin_password='" 
    .md5($_POST['admin_password']) . "' 
    admin_firstname='" 
    $_POST['admin_firstname'] . "' 
    admin_lastname='" 
    $_POST['admin_lastname'] . "' ";
     echo 
    $query

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    Beautiful Rhode Island, USA
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like you're missing the commas in your SQL (all the field='values' need to be separated by commas:

    PHP Code:
    $query "INSERT INTO admin SET 
    admin_username='" 
    $_POST['admin_username']. "',
    admin_password='" 
    .md5($_POST['admin_password']) . "' ,
    admin_firstname='" 
    $_POST['admin_firstname'] . "' ,
    admin_lastname='" 
    $_POST['admin_lastname'] . "' ";
     echo 
    $query

  3. #3
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is an SQL syntax problem as opposed to a PHP one. I think commas are the only problem, although I'd recommend backticks around identifiers too.
    PHP Code:
     $query "INSERT INTO `admin` SET
    `admin_username`='" 
    $_POST['admin_username']. "',
    `admin_password`='" 
    .md5($_POST['admin_password']) . "',
    `admin_firstname`='" 
    $_POST['admin_firstname'] . "',
    `admin_lastname`='" 
    $_POST['admin_lastname'] . "' ";
    echo 
    $query
    You should also make sure you're protected against SQL injections.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks it workd


Bookmarks

Posting Permissions

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