I'm trying to make a php page with a login by copying a fragment that a partner passed me but at the time of executing it I skip that error:
Fatal error: Call to a member function fetch_assoc () on boolean.
I do not know how to solve it; this is the code:
<?php
if(isset($_POST["login"])){
$mysqli = new mysqli('localhost','toni','','ssf');
if(!$mysqli->connect_errno){
$mysqli->set_charset("utf8");
$Usuario = $_POST['Usuario'];
$Contrasena = $_POST['pw'];
$Admin = $_POST['Usuario'];
$Contra = $_POST['pw'];
if($_POST['Tipo'] == "cliente"){
$result = $mysqli->query("SELECT * FROM usuario WHERE Usuario='$Usuario' AND Contrasena='$Contrasena'");
if(mysqli_num_rows($result)>0){
setcookie("login",$_POST['usuario'],time() + (86400 * 30),"/");
$_COOKIE["login"] = $_POST["usuario"];
$Admin=false;
}
else{
echo "Login Incorrecto";
}
}
else{
$results = $mysqli->query("SELECT * FROM usuario WHERE Usuario='$Usuario' AND Contrasena='$Contrasena'");
if(!$results || mysqli_num_rows($results)>0){
setcookie("login",$_POST['Usuario'],time() + (86400 * 30),"/");
$_COOKIE["login"] = $_POST["Usuario"];
$row = $results->fetch_assoc();
$Admin= $row["Tipo"] == "Admin" ? true : false;
}
else{
echo "Ni lo intentes";
}
}
}
}
?>