Jump to content

Help - Variable Keeps Resetting - Dynamic Text


oliverj777

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.