Home > Net >  php can't read http post request body
php can't read http post request body

Time:10-18

I've been stuck in this problem for two weeks. I have a flutter app and I'm trying a simple login with a username and password and I'm checking if there's a match to the username and password in the data base. I'm using php as a back-end but it seems that php can't see the post request body at all. I tried it at postman and even if the username and password are correct it always gives me "Invalid Username or password please try again". I think that it returns an empty response but I don't know why.

the status code= 200.

php code:

    <?$con = include "conn.php";
    $json = file_get_contents('php://input');
   $obj = json_decode($json);

    $username = $obj['username'];

  $password = $obj['password'];

  $loginQuery = "select * from user where username = '$username' andpassword = '$password' ";

 $check = mysqli_fetch_array(mysqli_query($con,$loginQuery));

if(isset($check)){
    
     $onLoginSuccess = 'Login Matched';
     
     $SuccessMSG = json_encode($onLoginSuccess);
     
     echo $SuccessMSG ; 
 
 }
 
 else{
    $InvalidMSG = 'Invalid Username or Password Please Try Again' ;
     
    $InvalidMSGJSon = json_encode($InvalidMSG);
     
     echo $InvalidMSGJSon ;
 
 }

 mysqli_close($con);
?>

Also when I print the $obj or $username to see what it has, it gives nothing.

Thanks if you made it so far and sorry for the long text. i will be very thankful if someone save me.

CodePudding user response:

I solved that. Basically I just created a new user table and it worked like magic.

  • Related