我知道以前有人问过这样的问题,我看过那些主题,但似乎仍然找不到我的语法错误-所以我转向张贴我自己的。
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 'INSERT_INTO users (uid,email,pass_hash,permissions,join_date) VALUES ('wright.ma' at line 1)
我的代码如下,但其他一切似乎工作,直到SQL,这似乎对我有效。
$email = $_POST['email'];
$pass = $_POST['pass'];
$pass2 = $_POST['pass2'];
$uid = $_POST['uid'];
$join_date = date("Y-m-d H:i:s");
if ($_POST['permissions']) { $permissions = $_POST['permissions']; } else { $permissions = 0; }
if (!$email) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("Security Module Error - Email address not provided");
}
if (!$uid) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("Security Module Error - User ID not provided");
}
if (!$pass || !$pass2 || ($pass != $pass2)) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("Security Module Error - Password not provided or doesn't match");
}
$pass_hash = crypt($pass,'$1$$hash$1');
$conn = @mysql_connect("localhost","root","root");
if (!$conn) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("Database Error - Unable to Connect");
}
$db = @mysql_select_db("start", $conn);
if (!$db) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("Database Error - Unable to Access Database");
}
$result = @mysql_query("INSERT_INTO users (uid,email,pass_hash,permissions,join_date) VALUES ('$uid','$email','$pass_hash','$permissions',$join_date)");
if (!$result) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("Database Error - Unable to Create Record (".mysql_error($conn).")");
}
$row = mysql_fetch_array($result);
if (!$row) {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
exit("Security Module Error - Unable to Authenticate Record Creation");
} else {
$_SESSION['uid'] = $row['uid'];
$_SESSION['permissions'] = $row['permissions'];
$_SESSION['email'] = $row['email'];
}
如果有人愿意帮忙,我将不胜感激! 用下划线分隔INSERT和INTO。语法应该是"INSERT INTO ...."
您还应该考虑使用PDO或mysqli,因为mysql_*函数已被弃用。
这应该是…
INSERT INTO users
不. .
INSERT_INTO users