Jump to content

[SOLVED] SELECT using a session variable


JCS1988

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

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.