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($string, 0, 3);
}
$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
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).
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).