I am working on my first login script. I have been following examples from a book, but this is where I am stuck. I want the user login to be an e-mail address, but when I would hit submit, I would get this error.
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\mysite\index.php on line 19
The script works from the book, there's no typos, and from Google, I found that error is given if the original query fails, so I decided to insert a "mysqli_error" to check what is wrong and I got this:
Nah. [email protected] have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@mysite.com AND password = SHA('password')' at line 1
So, I am almost positive that the @ sign is ending my query early. I have trim and mysql_real_escape_string as a way to clean up the strings, but besides that I have nothing. I have been Googling for a while now and I can't find or figure out how to make an exception for the @ ("at sign") or some kind of work around.
I didn't want this question to be too long or complicated, but I can provide more code if needed.
Thanks!
Edit: Here is the complete code to narrow down the solution.
if (isset($_POST['submit'])) {
$loginEmail = mysqli_real_escape_string($dbc, trim($_POST['loginEmail']));
$loginPassword = mysqli_real_escape_string($dbc, trim($_POST['loginPassword']));
$query = "SELECT user_id, username FROM user_db WHERE email = $loginEmail AND password = SHA('$loginPassword')";
$loginData = mysqli_query($dbc, $query);
if (mysqli_num_rows($loginData) == 1) {
echo 'You win!';
}
else {
$error = mysqli_error($dbc);
echo 'Nah. ' . $loginEmail . $error;
}
}