-2

This is the error:

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

The code where the error happens:

$numrows = mysql_num_rows($result);

Here is my full code:

<?php
session_start();
include("databases/connection.php");

if ( isset($_POST['username']) && isset($_POST['password']) ) {

    $q = sprintf("SELECT * FROM admins WHERE username = '%s' AND    password = '%s'",
        mysql_real_escape_string($_POST['username']),
        mysql_real_escape_string(md5($_POST['password']))
    );

    $result = mysql_query($q);
    $numrows = mysql_num_rows($result);
    if ( $numrows > 0 ) {
        $_SESSION['id'] = mysql_result($result, 0, "id");
        $_SESSION['name'] = mysql_result($result, 0, "name");
        $_SESSION['usertype'] = mysql_result($result, 0, "userlevel");

        echo '<script>alert("Congratulations you successfully logged in");window.location="/mikez/carting/index.php";</script>';
    } else {

        echo '<div class="alert alert-info">
        <a href="/mikez/carting/index.php" class="close" data-dismiss="alert" aria-label="close">&times;</a>Invalid username and password
        </div>';
    }
}
?>  

Thanks for advice! ^_^

Axel Guilmin
  • 10,924
  • 9
  • 51
  • 60

1 Answers1

0

Probably your MySQL credentials in include("databases/connection.php"); are not working, check if they are still valid (phpmyadmin or whatever you have available)

the-noob
  • 1,304
  • 2
  • 14
  • 19