Problem using session. Why can't get the values of $_SESSION

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpguy4
Forum Newbie
Posts: 2
Joined: Wed Sep 02, 2009 4:13 am

Problem using session. Why can't get the values of $_SESSION

Post by phpguy4 »

Hi, Guys

I have a problem using session. I set the session variables in the previous page, then when I use those variables at the next page, there is nothing in the variable. The following is the code that I wrote.

First Page:

Code: Select all

 
<?php 
if (!isset($_SESSION['position']))
{ $_SESSION['position'] = "curr";}
 
if (!isset($_SESSION['clientid']))
{$_SESSION['clientid'] = "1";} 
?>
 
Second Page:

Code: Select all

 
$db_name = "poll";
$table_name = "cinfo";
$connection = @mysql_connect("localhost", "p", "111") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
SWITCH ($_SESSION['position']) 
 { CASE "curr":
 $result = @mysql_query("SELECT clientid FROM $table_name WHERE clientid = $_SESSION['clientid'] ORDER BY serno");
  break;
 CASE "next":
 break;
 CASE "prev":
  break;
 CASE "first":
  break;
 CASE "last":
 break;
 }
?>
 
My intention is to move record next, previous, first, last from the given clientid. Would you give me any way to implement
this intention and why the contents of the session variables don't move to next page. And as I know, the line
$result = @mysql_query("SELECT clientid FROM $table_name WHERE clientid = $_SESSION['clientid'] ORDER BY serno"); has a parsing error. Thank you for your help in advance.
Last edited by phpguy4 on Wed Sep 02, 2009 11:18 am, edited 2 times in total.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Problem using session.

Post by papa »

Do you have session_start() at the start of every page ?
phpguy4
Forum Newbie
Posts: 2
Joined: Wed Sep 02, 2009 4:13 am

Re: Problem using session.

Post by phpguy4 »

Hi,

Thanks for your quick reply. Actually yes, I did it before. But it made a warning continuously. So used sessions without
session_start() function. With session_start() function, I had a same result. I couldn't get the values from $_SESSION.
Thank you for your help.
Post Reply