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
Share on other sites

What's not possible?  The variable is passed onto other PHP pages using a session.

 

I just need to check for the variable (which choice chosen) in subsequent pages and I'm trying to figure out the best way to do that.

Link to comment
Share on other sites

Actually I am able to accomplish what I want now with MUCH simpler code.  I just set a session variable on a page and reference it later to put it very simply.  Anyways it's working as I intended so I'm out.

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.