Reputation: 65
Having a bit of trouble passing a session variable into a mysql query in php. Tried putting it into a variable and testing against that and no luck. Also tried various formatting already. At a loss. It's just a simple string passed in.
$result = mysqli_query($db_connection, "SELECT * FROM feedback WHERE StudentID=" . $_SESSION['BCode'] . "");
Upvotes: 1
Views: 436
Reputation: 477
Are you setting:
session_start();
at the header of your .php file?
<?php
session_start();
$studentid = $_SESSION['BCode'];
$result = mysqli_query($db_connection, "SELECT * FROM feedback WHERE StudentID='" . $studentid . "'");
$finalResult = array();
while ($row = $result->fetch_assoc())
{
$finalResult[] = $row;
}
$jsonoutput = json_encode($finalResult); // Encodes the query result into JSON
?>
Upvotes: 3
Reputation: 11081
Check for session_start();
and try
mysqli_query($db_connection, "SELECT * FROM feedback WHERE StudentID='" . $_SESSION['BCode'] . "'");
Upvotes: 1