Search code examples
mysqlauthenticationwarningsphp-5.4

php login system warning


I'm trying to make a log in system using PHP (5.4) I have two problems I can't seems to figure out. Problem one is when I try to long in using the system I get this warning

"Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\MyFirstProject\login.php on line 17"

Second problem I have is that instead of logging in it tell me my password or email address is incorrect even though I know that I'm typing in the practice email and password correctly.

I have looked over this code over and over and can't figure out whats wrong, also for now I have it dying just so I can debug it enough to get it to work then I'll move on to the next step. Any help would be appreciated. Thanks

Code:

<?php
require("config.php");

if (isset($_POST['submitButton'])) {
   if (!isset($_POST['email'])) {
       die("<strong>Error:</strong> The email field was not set.");
   } else if (!isset($_POST['password'])) {
       die("<strong>Error:</strong> The password field ws not set.");
   }

   $password = hash("sha512", $_POST['password']); 

   $query = mysql_query("SELECT `id` FROM `users` WHERE `email` = '" 
           . mysql_real_escape_string($_POST['email']) . "' AND `passoword` = '" 
           . mysql_real_escape_string($password)  . "'");

   if (mysql_num_rows($query)) {
       die("Login credentials correct!");
   }  else {
       die("<strong>Error:</strong> Incorrect password or email address.");
   }
}

?>

Solution

  • Check inside your query: there is a typo. Passoword instead of password.