Help with the error: Trying to get property of non-objet

2

When this code is executed

<?php
    session_start();
?>

<?php
    $host_db="localhost";
    $user_db="root";
    $pass_db="";
    $db_name="Proyecto";
    $tbl_name="Usuarios";

    $conexion= new mysqli($host_db, $user_db, $pass_db, $db_name, $tbl_name);

    if($conexion->connect_error){
        die("La conexión fallo: ".$conexion->connect_error);
    }

    $User_Name=$_POST['User_Name'];
    $Contrseña=$_POST['Contraseña'];
    $sql="SELECT * FROM $tbl_name WHERE Nombre_Usuario='$User_Name'";
    $result= $conexion->query($sql);

    if($result->num_rows>0){
        $row=$result->fetch_array(MYSQLI_ASSOC);    
    }
   
    if(password_verify($Contrseña,$row['Contraseña'])){
        $_SESSION['loggedin']=true;
        $_SESSION['User_Name']=$User_Name;
        $_SESSION['strart']=time();
        $_SESSION['expire']=$_SESSION['start']+(5*60);

        echo "¡Bienvenido!".$_SESSION['User_Name'];
        echo "<br><br><a href=panel-control.php>Panel de Control</a>";
    }
    else{
        echo "Usuario y/o Contraseña son incorrectos.";
        echo "<br><a href='login.html'>Volver a Intentarlo</a>";
    }

    mysqli_close($conexion);    
?>

I get this error

  

Trying to get property 'num_rows' of non-object in Line 23

    
asked by Camilo Ramirez 22.08.2018 в 23:18
source

1 answer

0

For the new connection version mysqli the property num_rows does not exist. You can try to modify your validation of line 23 by:

if(mysqli_fetch_assoc($result)){
  $fila=mysqli_fetch_assoc($result);
}
    
answered by 23.08.2018 в 07:36