I have been following some tutorials and created the following prepared statement however it is not working on my website. I'm trying to use the session variable to display data from 2 tables.
$db_id = $_SESSION['customerID'];
$query = "SELECT * FROM booked_activities INNER JOIN activities ON booked_activities.activityID = activities.activityID WHERE booked_activities.customerID=?";
$stmt = mysqli_stmt_init($connection);
//prepare the prepared statement
if(!mysqli_stmt_prepare($stmt, $query)){
echo "SQL statement failed";
} else {
//bind parameters to the placeholders
mysqli_stmt_bind_param($stmt, "i", $db_id);
//run parameters inside database
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
echo "<table border='1'>
<tr>
<th>Activity</th>
<th>Date</th>
<th>Tickets</th>
</tr>";
while($row = mysqli_fetch_array($query))
{
echo "<tr>";
echo "<td>" . $row['activity_name'] . "</td>";
echo "<td>" . $row['date_of_activity'] . "</td>";
echo "<td>" . $row['number_of_tickets'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
Can anybody spot what is wrong with my code? I need to use the $db_id as its the common field in the two tables.