Jump to content

Recommended Posts

I did a lot of searching and found similar problems, but the situations were a bit different than mine and I was unable to get it work with the codes I found. I'm sure there is a very simple solution to this, but I don't know it so maybe someone can help me out.

 

I have a page that sets a session

$_SESSION['SESS_CUSTOMER_ID']=$customer['customer_id'];

 

On the next page I would like to retrieve the customer id from the session and use it in a query to select all of the information about the customer in the table. I have a recordset setup in Dreamweaver to post all of the information into a dynamic table, I just seem to be having trouble getting that session variable to be read. Here is a sample of what it would look like, I just need to figure out how to insert the session.

 

$query_userSet = "SELECT * FROM users WHERE customer_id = $_SESSION['SESS_CUSTOMER_ID'];

 

 

Link to comment
https://forums.phpfreaks.com/topic/90142-solved-select-using-a-session-variable/
Share on other sites

Write you query like:

<?php
$query_userSet = "SELECT * FROM users WHERE customer_id = '" . $_SESSION['SESS_CUSTOMER_ID'] . "'";
?>

or

<?php
$query_userSet = "SELECT * FROM users WHERE customer_id = '{$_SESSION['SESS_CUSTOMER_ID']}'";
?>

 

I use the first method, but that's just my style.

 

Make sure you have a session_start(); at the start of your script.

 

Ken

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.