0

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
DeeJJx
  • 11
  • 4
  • I believe you need to call `mysqli_fetch_array()` on either `$stmt` or `$result` - I use PDO myself and it's a bit different. But you're calling it on the query string, and that won't work. If that doesn't help, please expand on "not working". – droopsnoot Jan 06 '21 at 13:19
  • thanks! Using $result worked – DeeJJx Jan 06 '21 at 13:22

0 Answers0