PHP Session Variables! Need help with the simplest thing!?

Phil M

New member
I need help. I am trying to carry 1 variable (username) from the login page to another. First of all, am I writing this code correctly?
session_start();

$_SESSION["$user_username"] = "username";

$user_username is the variable I use from the login script on the login page which equals username (form field)
username is equal to form field from the login.

Then once I register this, does it have to be on every page? Also, if I want to call it up as a GET on the next page, can I do that?

Trying to write a query as well.
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

$query = "SELECT * FROM casesubmission WHERE username=+$user_username";
$result = mysqli_query($dbc, $query)
or die ('Error Querying Database.');

$row = mysqli_fetch_array($result);

echo $row['city'];

what am I doing wrong. This may be the code for an actual manual query. I am trying to pull up information on the main menu after login using the username from login page. The form refers to itself and the form is POST on the login and somehow I need a GET as well. Any Suggestions?
 
You do not set a session variable with a variable. You want a session variable called user_username correct?
This is wrong:
$_SESSION["$user_username"] = "username";
This is correct:
$_SESSION["user_username"] = "username";

Once this variable is set, it can be used on anypage. For example, you went to a different page, you simply type:
echo $_SESSION["user_username"];
and it will be echo'd onto the page.
Good Luck!
If you need further assistance/advice, feel free to contact me.
 
Back
Top