I realize the error pertains to syntax - I am fairly new to MySQL; but I usually know my way around. This error has been plaguing me for days! Any and all help would be appreciated, thanks!
ERROR:
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 (I narrowed it down to these two functions, addUser() calls 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";
}
}