-1

I am receiving this error

Warning: mysql_num_rows() expects parameter 1 to be resource

when trying to login with the username/password I have created. its giving me error on this line of code

if(mysql_num_rows($checklogin) == 1)

here is code around it

 $checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");

    if(mysql_num_rows($checklogin) == 1)
    {
        $row = mysql_fetch_array($checklogin);
        $email = $row['EmailAddress'];

        $_SESSION['Username'] = $username;
        $_SESSION['EmailAddress'] = $email;
        $_SESSION['LoggedIn'] = 1;

        display_user_profile();
    }
jarlh
  • 42,561
  • 8
  • 45
  • 63
DontMatter
  • 11
  • 5
  • This is a popular question here - your query failed and produced a boolean `false` result, which you are using without checking first that it is valid. Additionally, there a some security issues with your code: SQL injection, unhashed passwords, unsalted passwords. – halfer Apr 26 '16 at 14:10
  • I checked it but i deleted the code for checking. I fixed it anyway – DontMatter Apr 26 '16 at 14:48
  • Possible duplicate of [mysql\_fetch\_array()/mysql\_fetch\_assoc()/mysql\_fetch\_row() expects parameter 1 to be resource or mysqli\_result, boolean given](http://stackoverflow.com/questions/2973202/mysql-fetch-array-mysql-fetch-assoc-mysql-fetch-row-expects-parameter-1-to) – halfer Apr 26 '16 at 15:17

1 Answers1

0

The mysql functions have all been deprecated and are no longer supported. You should strongly consider switching to PDO (http://php.net/manual/en/ref.pdo-mysql.php).

raphael75
  • 2,982
  • 4
  • 29
  • 44