This may be a vary dumb question with a very simple answer. I hope…
This is a class project, yes I am new to php, however I am having fun.
Anyway, my question is this: Can I use a SESSION variable in a PHP/MYSQLI statement
to run a query on a database?
I use the code below in other areas using $_POST, however, it does not seem to work using SESSION.
I take the where clause out and the table data prints fine. My goal is to get specific user information,
from a user that is already logged in, not the whole table. The echo statement below prints fine, I put that there
to verify the session passed the variable.
[code]<?php
removed DB connection info
if (mysqli_connect_errno())
{
printf("Connect failed: %sn", mysqli_connect_error());
exit();
}
if($result=$DBConnect->query("SELECT User_ID, Username, Password FROM tbl_users WHERE Username = {$_SESSION['Username']}"))
{
while($fieldData=$result->fetch_object())
{
echo 'Your ID:'.$fieldData->User_ID.'
‘;
echo ‘Your Username:’.$fieldData->Username.’
‘;
echo ‘Your Password:’.$fieldData->Password.’
';
}
}
echo $_SESSION[‘Username’];
$DBConnect->close();
?>[/code]