num_rows一直返回null [重复]

This question already has an answer here:

I honestly can't see why this doesn't work. I have checked it several times even compared it to other examples I have done that does work. Please note that I have taken it down to the simplest form so there is no sql injection protection. That comes later.

//user real escape string to prevent SQL injection
$username = $_POST['username'];
$password = $_POST['password'];

//check if username and password is blank
if (!$username || !$password)
    die ("Not all the fields were filled in");

//Server details
$host = 'localhost';
$user = 'tm_user';
$password = 'password';

//The database name
$database = 'TransportMe';

// Create connection
$con = new mysqli($host, $user, $password, $database);

// Check connection
if ($con->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

//since user and password is not blank, find user info using the email and password entered by user
$sql= "SELECT * FROM Users WHERE 'email'='$username' AND 'password' = '$password';";

//Get the results
$result = $con->query($sql);

//Check if null
if ($result->num_rows == null)
    die("Null");
</div>

use backticks for columns in your query like this

$sql= "SELECT * FROM Users WHERE `email` = '$username' AND `password` = '$password'";

Your query should be:

//since user and password is not blank, find user info using the email and password entered by user
$sql= "SELECT * FROM `Users` WHERE `email` = '{$username}' AND `password` = '{$password}';";