I have a code in php which I want to consume in android, the problem I currently have is that when testing the code, I have problems with it, the error I have is when executing the query with the variable "$result" of the authenticate function, since it gives me the following alert message
mysqli_num_rows() expects parameter 1 to be mysqli_result
The code I have is the following:
class User {
private $db;
private $conexion;
function __construct() {
$this -> db = new Conexion();
$this -> conexion= $this->db->obtenerConexion();
}
public function autenticar($email,$password){
$jsonData= array();
$query = "SELECT * FROM `usuarios` WHERE email='$email' and contraseña='$password'";
$result = mysqli_query($this->conexion, $query);
if(mysqli_num_rows($result)>0){
while ($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$jsonData['Estado'] [] = 'correcto';
$jsonData['nombre'] []=$row['nombre'];
$jsonData['codigo'][]= $row['codigo'];
$jsonData['foto'][]=$row['FotoPerfil'];
}
}
else{
$jsonData['Estado'] = 'Error, credenciales invalidas';
}
$json['Login_data']=$jsonData;
echo json_encode($json);
mysqli_close($this -> conexion);
}
}
$user = new User();
if(isset($_POST['email'],$_POST['password'])) {
$email = $_POST['email'];
$password = $_POST['password'];
if(!empty($email) && !empty($password)){
$user-> autenticar($email,$password);
}else{
$json['Estado'] = 'Error, campos vacios';
echo json_encode($json);
}
}else{
$json['Estado'] = 'Error, variables sin contenido de Post';
echo json_encode($json);
}
?>
I hope you can help me
The problem is in the password ñ, change the name of the field to password for example. I'm glad it works :)