jeudi 30 juin 2016

Where Command not Working while fetching a data

<?php

$hostname="localhost";
$user="root";
$pass="";
$dbname="testdb";

$db=mysqli_connect($hostname,$user,$pass,$dbname);
if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$username = $_POST["Email"];
$password = $_POST["Password"];
$statement=mysqli_prepare($db,"SELECT * FROM login WHERE Email = ? AND Password = ?");
mysqli_stmt_bind_param($statement,"s",$username,$password);
mysqli_stmt_execute($statement);

 mysqli_stmt_store_result($statement);
 mysqli_stmt_bind_result($statement,$username,$password);

 $response = array();
  $response["success"] = false;

while(mysqli_stmt_fetch($statement)){
    $response["success"] = true;
$response["username"] = $username;
$response["password"] = $password;

}

echo json_encode($response);

?>

So i am trying to create a baisc Login Page and this is my code. The Datatype of Email and Password are both Varchar(40) in the table and Email is my primary Key.

It is returning succes as false even though the data is present. Basically it is not doing the query part efficiently. I have tried coding it in all way possible, OOP and Procedural ,mysql and mysqli and everything else. Can someone help me out here .

Aucun commentaire:

Enregistrer un commentaire