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();

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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