Jump to content

passing variable(s) based on user choice


muze

Recommended Posts

I'm trying to code the following situation, where there is a sort of choose your own adventure game for the user.  I want some of the choices (designated as links into series of pages) to have variables attached to be called later (like if the "story" returns to a common page).  I don't want to use a database or a form.  I'm hoping I can do this with an array.  I am able to successfully pass variables using $_SESSION.  Here's the (bad) code I'm working on:

 

	<? 

$choice[one]="<p><a href='page1.php'>Do this</a></p>";
$choice[two]="<p><a href='page2.php'>Do that</a></p>";


foreach ($choice as $value) {

echo $value;
$_SESSION['value']=$value; //probably not necessary or useful but I need to somehow pass these values to the next page to check for them.

}

  $_SESSION['choice']=$choice;
  
  ?>

 

I have

<?
session_start();
?>

at the tops of the pages

 

Then on page1.php I have

 

if	($_SESSION['choice'] = "one") {
		echo "one;}
		else{
			echo "two";}	

  ?>

 

So I'm sure it's a mess.  If anyone can help, please respond.

Link to comment
https://forums.phpfreaks.com/topic/208391-passing-variables-based-on-user-choice/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.