I want the following code to return the userID from mysql tblUser of the user if the email and password matched. Currently it is not returning anything
<?php
include 'config.inc.php';
// Check whether username or password is set from android
if(isset($_POST['email']) && isset($_POST['password']))
{
// Innitialize Variable
$result='';
$email = $_POST['email'];
$password = $_POST['password'];
// Query database for row exist or not
$sql = 'SELECT UserID FROM tblUser WHERE email = :email AND password = :password';
$stmt = $conn->prepare($sql);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->execute();
if($stmt->rowCount())
{
$result="true" . UserID;
}
elseif(!$stmt->rowCount())
{
$result="false";
}
// send result back to android
echo $result;
}
?>
password_hash()
andpassword_verify()
. If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionallity. - M. ErikssonUserID
in your code to get the result (that's, most likely, an undefined constant). You need to read the manual about how to get the result: php.net/manual/en/pdostatement.fetch.php - M. Erikssonelseif
in that statement. You only needelse
since there can only be two states for that expression. - M. Eriksson