I want to make a login for a class (so I'm not looking into preventing SQL injections right now) and I'm having trouble making use of the row counting to see if I can login or not.
How could I count the rows from the selection? I've tried some things which just didn't work.
The error I get is in the line that has a comment.
$host = "localhost";
$serverusername = "root";
$serverpassword = "";
$database = "usuarios";
$table = "user";
$username = $_POST['username'];
$password = $_POST['password'];
$mysqli = new mysqli($host, $serverusername, $serverpassword, $database);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$query = "SELECT * FROM ".$table." WHERE `username` = ".$username." AND `password` = ".$password;
$result = $mysqli->query($query);
$row = $result -> num_rows; //this line has an error. Trying to get property of non-object
if ($row != 0)
{
header('Location : index.html');
die();
}
else
{
echo "password incorrecta!";
}
$mysqli -> close();