我意識到錯誤屬於語法 - 我對MySQL相當新;但我通常知道我的方式。這個錯誤一直困擾着我好幾天!任何和所有的幫助,將不勝感激,謝謝!MySQL錯誤#1064無法找到解決方案?
錯誤:
Connected successfully! SQLSTATE[42000]: Syntax error or access violation: 1064 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 '' at line 1 USER EXISTS
CODE(我把範圍縮小到這兩個功能,ADDUSER()調用doesUserExist()):
function doesUserExist($user, $conn) {
try {
// Setting the query and runnin it...
$sql = "SELECT COUNT(email) FROM userinformation WHERE email = $user";
$result = $conn->query($sql);
// If it's greater than 0 then the account exists
if ($result != 0) {
echo "more than 0";
return true; // user exists
} else {
echo "0";
return false; // user does not exist
}
}
// Catching it if something went wrong.
catch(PDOException $e) {
echo $e->getMessage();
}
}
function addUser($user, $conn) {
echo $user;
// If user does not exist
if (doesUserExist($user, $conn) === false) {
// Add user to database (begin this process)
$sqlEntry = "INSERT INTO userinformation (email, password) VALUES('alexnord', 'password')";
$query = $conn->query($sqlEntry); // insert data into table
} else {
// Take to profile homepage
echo "USER EXISTS";
}
}
請使用PHP的[內建函數](http://jayblanchard.net/proper_password_hashing_with_PHP。 html)來處理密碼安全性。如果您使用的PHP版本低於5.5,則可以使用'password_hash()'[兼容包](https://github.com/ircmaxell/password_compat)。 –