Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    registration script syntax eror

    Hi,
    I am trying to make a registration script and when I run the code below, I get this error message:
    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 'group ) VALUES ( 'theusernameiposted' , '6032e6baa29d1f72eef838fabd7987cbfa3a11f7549d' at line 1
    I presume it is just an extra comma or something but I can't spot it!

    Any help is greatly appreciated!

    Thanks

    PHP Code:
    // my connect and choose database script goes here
    $username $_POST['myusername'];
    $password $_POST['mypassword'];
    $group $_POST['group'];
    if(
    strlen($username) > 30)
        
    header('Location: register.php');
    $hash hash('sha256'$password);
    function 
    createSalt()
    {
        
    $string md5(uniqid(rand(), true));
        return 
    substr($string03);
    }
    $salt createSalt();
    $hash hash('sha256'$salt $hash);
    $username mysql_real_escape_string($username);
    $query "INSERT INTO users ( username, password, salt, group )
            VALUES ( '$username' , '$hash' , '$salt' , '$group' )"
    ;
    mysql_query($query)or die(mysql_error());
    mysql_close();
    echo 
    "The new user has been created.  Thank you."
    Last edited by jake66; 01-04-2012 at 09:25 PM. Reason: resolved

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    DEBUG DEBUG DEBUG.

    Code:
    echo "<hr>DEBUG SQL: " . $query . "<hr>";
    what does that show?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,304
    Thanks
    4
    Thanked 204 Times in 201 Posts
    group is a reserved word in MySQL which means you'd need to enclose it with back ticks (`) to tell MySQL it's a column name (or choose another name for that column).

    Code:
    $query = "INSERT INTO users ( username, password, salt, `group` )
            VALUES ( '$username' , '$hash' , '$salt' , '$group' )";
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    jake66 (01-04-2012)

  • #4
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djm0219 View Post
    group is a reserved word in MySQL which means you'd need to enclose it with back ticks (`) to tell MySQL it's a column name (or choose another name for that column).

    Code:
    $query = "INSERT INTO users ( username, password, salt, `group` )
            VALUES ( '$username' , '$hash' , '$salt' , '$group' )";
    Thank you very much! Problem solved.
    I did not know about reserved words...are there many?

  • #5
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,304
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Dave .... HostMonster for all of your hosting needs

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    DOH on me. I saw password there and thought maybe it was reserved, but looked it up and saw it wasn't. Didn't even notice group.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,304
    Thanks
    4
    Thanked 204 Times in 201 Posts
    I too was a bit surprised that password wasn't a reserved word. The error message he posted gave me the clue about group being the culprit.
    Dave .... HostMonster for all of your hosting needs

  • #8
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djm0219 View Post
    crikey, that is a long list!
    Thanks very much!


  •  

    Tags for this Thread

    Posting Permissions

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