Jump to content

[SOLVED] Help With PHP MYSQLI Statement Using Session Variables


devwalt

Recommended Posts

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 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.

 

 

<?php

removed DB connection info

 

if (mysqli_connect_errno())

{

printf("Connect failed: %s\n", 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.'<br />';

echo 'Your Username:'.$fieldData->Username.'<br />';

echo 'Your Password:'.$fieldData->Password.'<br />';

 

}

 

}

 

echo $_SESSION['Username'];

 

 

 

$DBConnect->close();

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.