Im trying to convert a working php script to prepared statement but I cannot get any results when i create a user and insert there data into the retrieve data fields i am getting “no records” message which means its reading rows as 0, when i know i am entering data that is inside database.
I am new to php, so please be kind.
<?php
$id = $_POST["email"];
$pwd = $_POST["password"];
$con=mysqli_connect("t","","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
$key = file_get_contents('../Door.txt', true);
$sql = "SELECT name,score FROM PlayerDetails WHERE email = ? AND password = AES_ENCRYPT(?,?)";
// $result = mysqli_query($con, $sql);
$stmt = mysqli_stmt_init($con);
if (!mysqli_stmt_prepare($stmt, $sql))
{
echo "SQL error";
} else{
mysqli_stmt_bind_param($stmt, "sbs", $id, $pwd, $key);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if($result->num_rows == 0)
{
echo "No records found.";
}
else if($result->num_rows >0)
{
$row = $result->fetch_assoc();
echo $row['name']. '|'.$row['score'];
}
}
mysqli_close($con);
?>