MySQL syntax error: I'm stuck
$queryStatus = mysql_query("INSERT into `database`.`users` (`first`, `last`, `pass`, `user`, `id`, `email`, `active`) VALUES ('$first', '$last', '$password', '$user', NULL, '$email', '0'") or die("BAD QUERY: " . mysql_error());
The ID field is NULL
because it is an auto-increment. But it is throwing a syntax error and I really can't find out why. Please help.开发者_开发技巧
Ignore the ID field, it will insert the value automatically:
$queryStatus = mysql_query("INSERT into `database`.`users` (`first`, `last`, `pass`, `user`, `email`, `active`) VALUES ('$first', '$last', '$password', '$user', '$email', '0'") or die("BAD QUERY: " . mysql_error());
Also your query seems badly formed (incorrectly places quotation mark at end), I'm not sure about PHP specifically but this should work:
$queryStatus = mysql_query("INSERT into `database`.`users` (`first`, `last`, `pass`, `user`, `email`, `active`) VALUES ('$first', '$last', '$password', '$user', '$email', '0')");
You do not close off the VALUES ()
part of the query. There needs to be a close bracket at the end - don't confuse it with the close bracket for the mysql_query
function call.
You have an extra double quotation mark (") right before the closing bracket that's stated before "or die".
精彩评论