troubleshooting Question

php session switch problem

Avatar of newbe101
newbe101 asked on
PHP
12 Comments1 Solution752 ViewsLast Modified:
Hi all,
I have a multipage form and I am using php sessions to remember the user form data.  I need to give the user the option of "jumping around" the multi page form rather than forcing the user to go through the form with the submit/reset html buttons.  So, in the nav links I have included a javascript to submit the form (... onclick="document.['byc'].submit(); return false" ...).  I have also included 2 variables in the url (which page coming from "a=page number" and which page going to "z=page number").  I am using php switch on the index.php page to check for the "from page" and the "to page" then include() the appropriate contents file.  When I had this setup using submit/reset html form buttons, everything was working fine.  Now that I need to use "jumpable" links, I can't seem to get the php session to get the user form data... please help.
:::index.php:::
<?
$color=$_GET["color"];
$rims=$_GET["rims"];
$ctop=$_GET["ctop"];
$z=$_GET["z"];
 
switch ($_GET['a']) {
  case '1': 
  	session_start();
  break;
  case '2':
  	session_start();
	session_register('test1');
	session_register('test2');
	session_register('test3');
	$_SESSION['test1'] = $_POST['test1'];
	$_SESSION['test2'] = $_POST['test2'];
	$_SESSION['test3'] = $_POST['test3'];
  break;
  case '3': 
  	session_start();
  break;
  case '4': 
  	session_start();
  break;
  default: $a = ''; break;
}
 
switch ($_GET['z']) {
  case '1': $z = "1.php"; break;
  case '2': $z = "2.php"; break;
  case '3': $z = "3.php"; break;
  case '4': $z = "4.php"; break;
  default: $z = "1.php"; break;
}
 
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BYC PHP Session Test</title>
</head>
 
<body>
<? include("nav.php"); ?>
<? include($z); ?>
</body>
</html>
:::EOF:::
 
:::nav.php:::
<form name="byc" method="post" action="<?=$z;?>">
<a href="index.php?rims=<?=$rims?>&color=<?=$color?>&ctop=<?=$ctop?>&a=1&z=1" onclick="document.['byc'].submit(); return false">Page 1</a> | 
<a href="index.php?rims=<?=$rims?>&color=<?=$color?>&ctop=<?=$ctop?>&a=1&z=2" onclick="document.['byc'].submit(); return false">Page 2</a> | 
<a href="index.php?rims=<?=$rims?>&color=<?=$color?>&ctop=<?=$ctop?>&a=1&z=3" onclick="document.['byc'].submit(); return false">Page 3</a> | 
<a href="index.php?rims=<?=$rims?>&color=<?=$color?>&ctop=<?=$ctop?>&a=1&z=4" onclick="document.['byc'].submit(); return false">Page 4</a><br />
:::EOF:::
 
:::2.php:::
<img src="gdimage.php?rims=<?=$rims?>&color=<?=$color?>&ctop=<?=$ctop?>">
<br />
test1 <input name="test1" value="<? if(isset($_SESSION['test1']))print $_SESSION['test1']; ?>" />
<br /> 
test2 <input name="test2" value="<? if(isset($_SESSION['test2']))print $_SESSION['test2']; ?>" />
<br />
test3 <input type="checkbox" name="test3" value="test3" <? if(isset($_SESSION['test3']))echo "checked"; ?> /><br />
<input type="submit" name="submit" value="Continue" /> 
</form>
<br />
<? print_r ($_SESSION); ?>
:::EOF:::
 
:::3.php:::
<img src="gdimage.php?rims=<?=$rims?>&color=<?=$color?>&ctop=<?=$ctop?>">
<br />
<?php
  print $_SESSION['test1'].'<br />';
  print $_SESSION['test2'].'<br />';
  print $_SESSION['test3'].'<br />';
?>
<br />
<? print_r ($_SESSION); ?>
<br />
<a href="index.php?rims=<?=$rims?>&color=<?=$color?>&ctop=<?=$ctop?>">Back to page 1</a>
<input type="submit" name="submit" value="Continue" /> 
</form>
:::EOF:::
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros