0

I'm retrieving users from my database with this php code below.

The problem is that when I execute the query without the AND condition, it works fine. With the AND condition it gives me always the else result.

   include("config.php");

$con=mysqli_connect($host,$username,$pwd,$db) or die('Unable to connect');
if(mysqli_connect_error($con))
{
   echo "Failed to Connect to Database ".mysqli_connect_error();
}

      $contact = mysqli_real_escape_string($con, $_GET['contact']);   
      $password = mysqli_real_escape_string($con, $_GET['motdepasse']);   

      $sql = "SELECT * FROM bonfoodUtilisateurs WHERE contact = '$contact' AND motdepasse = '$password'";
      $result = mysqli_query($con,$sql);
      $response = array();

      if (mysqli_num_rows($result)!=0) {
         $response['code'] = '1';
         $response['message'] = 'success message.';   
         echo json_encode($response);
         mysqli_close($con);
      }else{
         $response['code'] = '2';
         $response['message'] = 'error message.';
         echo json_encode($response);

         mysqli_close($con);
      }


?>

I'm expecting to get a result like ```{"code":"2","message":"error message."} 
if the user's ```contact and ```password don't exist in the data table
otherwise get ```{"code":"1","message":"success message."}

0 Answers0