oliverj777 Posted November 16, 2011 Share Posted November 16, 2011 Hello, I'm working on a dynamic text form (I guess thats what its called). Basically, I have a html page that echos in some PHP code. What the PHP code does is show different strings of text depending on a variable: <PHP? $brief1_info = "brief info goes here"; $brief1 = 0; if (isset($_POST['brief1Go'])) { $brief1 = $brief1 + 1; } else if (isset($_POST['brief1Back'])) { $brief1 = $brief1 - 1; } $breif1Controller = " <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"submit\" name=\"brief1Back\" id=\"brief1Back\" value=\"BACK\" /> </form> <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"submit\" name=\"brief1Go\" id=\"brief1Go\" value=\"CONTINUE\" /> </form>"; if($brief1 == 0){ $brief1_info = "<b>Welcome Commander,</b> you are currently viewing the Mission Control Brief page, here you can view all your missions that you need to complete in order to advance through your prestiges. You will need to follow your briefs carefully in order to succeed. <br /><br /> "; } else if($brief1 == 1){ $brief1_info = "Okay, let me show you around the place ..."; } else if($brief1 == 2){ $brief1_info = "brief is on 2"; } ?> The problem is, the BACK and CONTINUE buttons don't work. If $brief1 equals 0, and the user presses continue, the is should go to 1, and the brief1_info string is changed (so some different text shows in my html). It actually works when brief1 is on '0', but when its on 1 and the user pressed continue, the brief1 is changed to 1, but because the submit button refreshes the page, the variable is re-read again, and thus is reset back to 0. Is there a way around this? Or is there a better method than what I'm doing? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/251222-help-variable-keeps-resetting-dynamic-text/ Share on other sites More sharing options...
maccy93 Posted November 16, 2011 Share Posted November 16, 2011 If you need a variable like that then you could place into a session variable, that way from your description the variable would not be reset when the script is reloaded. Quote Link to comment https://forums.phpfreaks.com/topic/251222-help-variable-keeps-resetting-dynamic-text/#findComment-1288547 Share on other sites More sharing options...
oliverj777 Posted November 16, 2011 Author Share Posted November 16, 2011 If you need a variable like that then you could place into a session variable, that way from your description the variable would not be reset when the script is reloaded. Please elaborate, I'm not that advanced at PHP. I sure would appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/251222-help-variable-keeps-resetting-dynamic-text/#findComment-1288554 Share on other sites More sharing options...
Drummin Posted November 16, 2011 Share Posted November 16, 2011 Give this a test EDIT: Updated <?PHP session_start(); if(isset($_SESSION['brief'])){ $brief1=$_SESSION['brief']; } else{ $brief1 = 0; } //$brief1_info = "brief info goes here"; Not used/remove if (isset($_POST['brief1Go'])) { $brief1 = $brief1 + 1; $_SESSION['brief']=$brief1; } else if (isset($_POST['brief1Back']) && $_SESSION['brief']>=1) { $brief1 = $brief1 - 1; $_SESSION['brief']=$brief1; } ?> <html> <head> <title></title> </head> <body> <?PHP $breif1Controller = "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">"; //Added conditions for showing BACK button/ if(isset($_SESSION['brief']) && $_SESSION['brief']>=1){ $breif1Controller .= "<input type=\"submit\" name=\"brief1Back\" id=\"brief1Back\" value=\"BACK\" />"; } //Here you can set the max number of briefings you've made// $maxbrief=2; if(!isset($_SESSION['brief']) || isset($_SESSION['brief']) && $_SESSION['brief']<$maxbrief){ $breif1Controller .= "<input type=\"submit\" name=\"brief1Go\" id=\"brief1Go\" value=\"CONTINUE\" />"; } $breif1Controller .= "</form>"; if($brief1 == 0){ $brief1_info = "<b>Welcome Commander,</b> you are currently viewing the Mission Control Brief page, here you can view all your missions that you need to complete in order to advance through your prestiges. You will need to follow your briefs carefully in order to succeed."; } else if($brief1 == 1){ $brief1_info = "Okay, let me show you around the place ..."; } else if($brief1 == 2){ $brief1_info = "brief is on 2"; } //Added so I could test echo "$breif1Controller"; if (isset($brief1_info)){ echo "$brief1_info"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/251222-help-variable-keeps-resetting-dynamic-text/#findComment-1288567 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.