JCS1988 Posted February 8, 2008 Share Posted February 8, 2008 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']; Quote Link to comment https://forums.phpfreaks.com/topic/90142-solved-select-using-a-session-variable/ Share on other sites More sharing options...
kenrbnsn Posted February 9, 2008 Share Posted February 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/90142-solved-select-using-a-session-variable/#findComment-462233 Share on other sites More sharing options...
JCS1988 Posted February 9, 2008 Author Share Posted February 9, 2008 Yep, first method worked perfect. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/90142-solved-select-using-a-session-variable/#findComment-462259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.