I'm sending json data from android volley post request for login system. How can I get the json data from android in php.
Android JSON structure:
{"email":"abc@gmail.com","password":"abcd"}
PHP Code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "phpsamples";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (isset($_POST['email']) && ($_POST['password'])) {
$json = file_get_contents('php://input');
$obj = json_decode($json);
$Email = $obj->{'email'};
$Password = $obj->{'password'};
//$email = $_POST['email'];
//$user_password = $_POST['password'];
$email = $Email;
$user_password = $Password;
$qry = 'SELECT * FROM `registered_users` WHERE `email`="'.$email.'" && `password`="'.$user_password.'"';
$login = mysqli_query($conn, $qry) or die(mysqli_error());
$no_of_row = mysqli_num_rows($login);
$row = mysqli_fetch_assoc($login);
if ($no_of_row == 1) {
$response["status"] = 1;
$response["message"] = "Login Success";
$response["id"] = $row['id'];
}
if (empty($email) || empty($user_password)) {
$response["status"] = 0;
$response["message"] = "Email and Password cannot be Empty";
} elseif ($no_of_row != 1) {
$response["status"] = 0;
$response["message"] = "Invalid Credentials";
}
} else {
$response["status"] = 0;
$response["message"] = "Invalid Request";
}
echo json_encode($response);