Select to return JSON [closed]

2

Hello! I have the following code in PHP:

login.php

<?php 
    $msg;
    if (isset($_POST['login']) && isset($_POST['senha'])) {
        $login = str_replace(" ", "", $_POST['login']);
        $senha = str_replace(" ", "", $_POST['senha']);

        if (strlen($login)<4 || strlen($login)>50) {
            $msg = array('status' => 0, 'msg' => "Login deve ter entre 4 a 50 caracteres!" );
        }elseif (strlen($senha)<8 || strlen($senha)>20) {
            $msg = array('status' => 0, 'msg'=> "Senha deve ter entre 8 a 20 caracteres");
        }else{
            require_once("logar.php");
        }
    }else{
        $msg = array('status' => 0, 'msg'=>"Informe o Usuario e Senha!");
    }
    echo json_encode($msg);
 ?>

logar.php

<?php 
    $login = $_POST['login'];
    $senha = $_POST['senha'];

    include "conexao.php";

    $sql = "SELECT * FROM usuario WHERE usuemail='$login' AND ususenha = MD5('$senha')";
    $resultado = mysqli_fetch_assoc($conexao->query($sql));
    if ($resultado) {

        $msg = array('status' =>1 , 'user' =>$resultado);

    }else{
        $msg = array('status' =>2 , 'msg' => "Usuario informado não existe!" );
    }


 ?>

In the cunsulta of the bank is certain, but I'm testing it in the ADVENCED REST CLIENT and only returns that the user does not exist. Can someone help me?

    
asked by anonymous 14.06.2017 / 14:24

1 answer

0

You are checking if a variable of type array is true: /, you actually have to check if it is empty or if a user has returned.

$row =mysqli_fetch_assoc($result);
if($row > 0){
   //....
}

or

if($row == 1){
  //....
}
    
14.06.2017 / 15:00