jaco Posted August 11, 2009 Share Posted August 11, 2009 Hello everyone, I have been banging my head on this topic and reduced the problem to 2 short example html pages. What I am trying to do is make sure that the status of a checkbox is maintained across 2 pages and that variables are passed from one page to the other. In the example code the first page (test.hp) allows the setting of a checkbox. When the submit button is pressed it calls the second (return-test.php) page where echo commands show if the variable has crossed to the page correctly. The submit button on this page returns to the 1st page. What is happening is that when the checkbox is checked after being unchecked the variable does not get transfered to the 2nd page but the first cycle of check and uncheck works fine, Son of a gun... Thanks fro any help, here is the code: test.hp <?php session_start(); echo "<html>"; echo "<head>"; echo "<body>"; if (!isset($_SESSION["count"])) { $_SESSION["count"]=0; $ch_leg = "on"; $_SESSION["ch_leg"] = "on"; } else { $_SESSION["count"]++; } echo "count =".$_SESSION["count"]; if ($_SESSION["count"] > 0) $ch_leg = $_SESSION["ch_leg2"]; echo "<br />"; echo "the value of ch_leg is = ".$ch_leg; echo "<FORM NAME =\"form2\" METHOD =\"GET\" ACTION =\"return-test.php\">"; echo "<INPUT TYPE = \"Submit\" Name = \"results\" VALUE = \"Go to RESULTS page\">"; if ($ch_leg == "on") echo "<Input type = \"Checkbox\" checked Name =\"ch_leg\" value =\"legacy_brand\">Legacy brand"; else echo "<Input type = \"Checkbox\" Name =\"ch_leg\">Legacy brand"; echo "</FORM>"; if ($_SESSION["count"] > 0) $_SESSION["ch_leg"] = $_GET["ch_leg"]; echo "</html>"; echo "</head>"; echo "</body>"; ?> and return.hp: <?php session_start(); $ch_leg2 =$_SESSION["ch_leg"]; $_SESSION["ch_leg2"] = $ch_leg2; echo "<html>"; echo "<head>"; echo "<body>"; echo "the value of session(ch_leg) is ".$_SESSION["ch_leg"]; echo "<br />"; echo "the value of ch_leg2 is ".$ch_leg2; echo "<br />"; echo "the value of SESSION(ch_leg2) is ".$_SESSION["ch_leg2"]; echo "<br />"; echo "count= ".$_SESSION["count"]; echo "<form action = \"test.php\">"; echo "Modifies number of pump data fields displayed "; echo "<input type=\"submit\" value=\"Modify Display\">"; echo "</form>"; echo "</html>"; echo "</head>"; echo "</body>"; ?> Cheers, Jacques Quote Link to comment Share on other sites More sharing options...
jaco Posted August 11, 2009 Author Share Posted August 11, 2009 I belive I have foound the solution. I needed to GET the var. in return.php. the correct code is: return-test.php <?php session_start(); $ch_leg = $_GET["ch_leg"]; $_SESSION["ch_leg"] = $ch_leg; echo "<html>"; echo "<head>"; echo "<body>"; echo "the value of session(ch_leg) is ".$_SESSION["ch_leg"]; echo "<br />"; echo "<br />"; echo "<br />"; echo "count= ".$_SESSION["count"]; echo "<form action = \"test.php\">"; echo "Modifies number of pump data fields displayed "; echo "<input type=\"submit\" value=\"Modify Display\">"; echo "</form>"; echo "</html>"; echo "</head>"; echo "</body>"; ?> and test.php: <?php session_start(); echo "<html>"; echo "<head>"; echo "<body>"; if (!isset($_SESSION["count"])) { $_SESSION["count"]=0; $ch_leg = "on"; $_SESSION["ch_leg"] = "on"; } else //session exists { $_SESSION["count"]++; $ch_leg = $_SESSION["ch_leg"]; } echo "count =".$_SESSION["count"]; echo "<br />"; echo "the value of ch_leg is = ".$ch_leg; echo "<FORM NAME =\"form2\" METHOD =\"GET\" ACTION =\"return-test.php\">"; echo "<INPUT TYPE = \"Submit\" Name = \"results\" VALUE = \"Go to RESULTS page\">"; if ($ch_leg == "on") echo "<Input type = \"Checkbox\" checked Name =\"ch_leg\">Legacy brand"; else echo "<Input type = \"Checkbox\" Name =\"ch_leg\">Legacy brand"; echo "</FORM>"; if ($_SESSION["count"] > 0) $_SESSION["ch_leg"] = $_GET["ch_leg"]; echo "</html>"; echo "</head>"; echo "</body>"; ?> Quote Link to comment 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.