I am pretty new with php, I have a MySql Php based backend which connects to a react native application.
I am handling invalid username and password but right username/password with wrong username/password and vice versa is where the app is getting force close (Crashed) as it cannot the entered data are not matching with the one that is in the database.
Can I know how can I achieve this?
Below is my php code for the same.
<?php
include 'DBConfig.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$json = file_get_contents('php://input');
$obj = json_decode($json,true);
$email = $obj['email'];
$password = $obj['password'];
$Sql_Query = "select * from UserRegistrationTable where email = '$email' and password = '$password' ";
$check = mysqli_fetch_array(mysqli_query($con,$Sql_Query));
if(isset($check)){
$SuccessLoginMsg = 'Data Matched';
$SuccessLoginJson = json_encode($SuccessLoginMsg);
echo $SuccessLoginJson ;
$response=array();
array_push($response,array("name"=>$check[1], "email"=>$check[2], "password"=>$check[3]);
echo json_encode(array("Details"=>$response));
}
else{
$InvalidMSG = 'Invalid Username or Password Please Try Again' ;
$InvalidMSGJSon = json_encode($InvalidMSG);
echo $InvalidMSGJSon ;
}
mysqli_close($con);
?>