It's been two days and I have not found any solution for this on Google, so please help.
I have to SELECT *
from one row with multiple WHERE
clauses, using a prepared statements, I want to retrieve the results using fetch_assoc
so that I don't have to bind variables using bind_result()
, using fetch_assoc
I can print many columns as $row['column_name']
. My code is below and it's not running, giving no error.
$query = 'SELECT * FROM `table_name` WHERE `uid` = ? AND `email` = ?';
if ($stmt_select = $conn->prepare($query)) {
$stmt_select->bind_param('is', $user_id, $user_email);
$user_id = $_SESSION['uid']; //this variable is set and prints perfectly
$user_email = $_SESSION['user_email']; //this variable is set and prints perfectly
$result = $stmt_select->execute();
$stmt_select->store_result();
while ($row = $result->fetch_assoc()) {
print_r($row);
echo $row["supermarket_name"];
echo $row["supermarket-region"];
/*Nothing is being printed*/
}
$stmt_select->free_result();
$stmt_select->close();
}else{
echo 'query returned false';
}
The var_dump($result)
returns (boolean)true
Since the above code isn't throwing any error and in last two days I couldn't figure out what's wrong with my code, can somebody let me know what's wrong with my code? Thanks!