Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-04-2012, 04:38 PM   PM User | #1
jake66
New Coder

 
Join Date: Jul 2011
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
jake66 is an unknown quantity at this point
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:
Quote:
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
jake66 is offline   Reply With Quote
Old 01-04-2012, 07:13 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 01-04-2012, 07:32 PM   PM User | #3
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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
djm0219 is offline   Reply With Quote
Users who have thanked djm0219 for this post:
jake66 (01-04-2012)
Old 01-04-2012, 07:35 PM   PM User | #4
jake66
New Coder

 
Join Date: Jul 2011
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
jake66 is an unknown quantity at this point
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?
jake66 is offline   Reply With Quote
Old 01-04-2012, 08:14 PM   PM User | #5
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
Quite a few http://dev.mysql.com/doc/refman/5.0/...ved-words.html
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Old 01-04-2012, 08:23 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 01-04-2012, 08:41 PM   PM User | #7
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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
djm0219 is offline   Reply With Quote
Old 01-04-2012, 09:24 PM   PM User | #8
jake66
New Coder

 
Join Date: Jul 2011
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
jake66 is an unknown quantity at this point
Quote:
Originally Posted by djm0219 View Post
crikey, that is a long list!
Thanks very much!
jake66 is offline   Reply With Quote
Reply

Bookmarks

Tags
mysql, register, syntax

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:07 PM.


Advertisement
Log in to turn off these ads.