I'm a newbie in PHP and mySQL, I'm currently working on a profile page where I will display the logged in user's personal information from one table called
users
and also display the tours that they will book in the future from my website from this table:
booking
I'm fetching the data from users table with prepared statement which will only select the data of logged in user without any problems, here is the code:
<?php
include_once 'php/connection.php';
$sess = $_SESSION['email'];
$sql="SELECT firstname, lastname, email, phone, birthday, gender FROM users WHERE email = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $sess);
$stmt->execute();
if ($stmt->error){echo "something has gone wrong";}
$result=$stmt->get_result();
while($row = mysqli_fetch_array ( $result, MYSQLI_ASSOC )) {
?>
I close the connection after the section where the data will be displayed with code:
<h2><?php echo $row["firstname"];?></h2>
<?php
}
$conn->close();
?>
However, I face the problem when I try to fetch data from both tables and display it on the page, I've done research and tried many options but it seems to be not working, here is what I've tried:
<?php
include_once 'php/connection.php';
$sess = $_SESSION['email'];
$sql="SELECT firstname, lastname, email, phone, birthday, gender
FROM users, booking
WHERE users.email = booking.email AND email = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $sess);
$stmt->execute();
if ($stmt->error){echo "something has gone wrong";}
$result=$stmt->get_result();
while($row = mysqli_fetch_array ( $result, MYSQLI_ASSOC )) {
?>
by using this script it's showing me this error:
Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in /storage/ssd1/136/16588136/public_html/profile.php:82 Stack trace: #0 {main} thrown in /storage/ssd1/136/16588136/public_html/profile.php on line 82
I've been trying to fix this problem all day but I can't come up with a solution. Could someone please help me out on this? Thanks in advance.