Page 1 of 1

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

Posted: Wed Sep 02, 2009 4:42 am
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.

Re: Problem using session.

Posted: Wed Sep 02, 2009 7:15 am
by papa
Do you have session_start() at the start of every page ?

Re: Problem using session.

Posted: Wed Sep 02, 2009 11:16 am
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.