Jump to content

Recommended Posts

hi there, i am trying to create a story for kids, that collects different information on each page, ie, the first page collects name, then goes to age.php, which collects age, then to gender etc. Whats the best way of using one of the variables on a later page?

 

ie

 

the first age collects a boys name called ben, i wish to say in the third page something like: ben, are you a boy or a girl.

 

cheers

Link to comment
https://forums.phpfreaks.com/topic/167510-variables-on-different-pages/
Share on other sites

is it possible to use sessions when the data is posted because im struggling with that! do i have the code correct below?

 

<?php session_start ();?>

<head>...

<body>

 

<?php

$name = $_POST['name']; ?>

 

<?php $_POST['name'] = $_SESSION['name']?>

 

</body>

</html>

The $_POST array automatically holds the values that you submitted from a form. What you do now is that you retrieve the form value and assign it to the variable $name. What you do next is that you assign the $_POST["name"] variable with the value stored in $_SESSION["name"]. You would want to do the opposite I assume:

 

$_SESSION["name"] = $name;

 

You don't really need $name though:

 

$_SESSION["name"] = $_POST["name"];

 

You might want to do some validation though on the posted values, depending on how you use them.

No, the two lines of code do the exact same thing. I just wanted to demonstrate that you didn't need that extra variable for this.

 

As long as the session doesn't time out you only need to set the variable once.

 

If the story is long you may want to add some features in order to make the application more user friendly though. Now, if the browser crashes (or they happen to close it for some other reason), they are not able to continue from where they were at. Children are usually more unpredictable than adults.

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.