Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Problem

Status
Not open for further replies.

markhkram

IS-IT--Management
Dec 30, 2008
32
0
0
US
So I have a problem with a Session. I have 2 sessions set on separate pages, but both post to index.php. Both work perfectly well on my machine I setup with php & MySQL. However when uploading to my 1&1 webhost, only the ResultsToDisplay will stay in session while I am logged in. The StateFilter session will not work when I upload to my 1&1 webhost. I have tried everything I can think of, but only the ResultsToDisplay will work on my webhost server, the StateFilter will always be blank. Here is my code for each session:

page1.php
Code:
<form method="post" action="index.php">
<select name="ResultsToDisplay">
     <option value="5">5</option>
</select>

index.php
Code:
<?php session_start(); ?>

$StateFilter=$_POST['StateFilter'];
$ResultsToDisplay=$_POST['ResultsToDisplay'];

if(isset($ResultsToDisplay)){
	$_SESSION['ResultsToDisplay']=$ResultsToDisplay;
}
if(isset($StateFilter)){
	$_SESSION['StateFilter']=$StateFilter;
}

<form method="post" action="./index.php" style="margin-bottom:0; margin-top: 0; display: inline;">
<select name="StateFilter" style="width: 100px; font size: 11px;" onchange=submit()>
<option value="All" <?php if(!isset($_SESSION['StateFilter'])){echo "SELECTED";}?>>All</font></option>
</select>
 
you have php code that is not within <?php ?> tags. this will not work.

also your conditional will never work
Code:
if(isset($ResultsToDisplay)){
    $_SESSION['ResultsToDisplay']=$ResultsToDisplay;
}

because $RresultsToDisplay is ALWAYS set by this code
Code:
$StateFilter=$_POST['StateFilter'];
$ResultsToDisplay=$_POST['ResultsToDisplay'];

if _POST is not set then the value will be NULL but it will be set.

you should instead do this

Code:
session_start();
foreach (array('ResultsToDisplay', 'StateFilter') as $var):
  if (!empty($_POST[$var])) $_SESSION[$var] = ${$var} = trim($_POST[$var]); 
endforeach;
this will populate $_SESSION and the $ResultsToDisplay (etc) only when the POST var is set.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top