Someone who know's PHP?

Liam Macmillan

New member
Hello, I am making a simple game with Javascript. The first page you see let's you choose a name.. Here is the code:

<form action="fuzzy.php?check" method="post">

Choose a name for your character: <input type="text" name="name" />

<input type="submit" value="Submit" />

</form>

So it echo's correctly on fuzzy's.php. But on Fuzzy's.php there is something you click which load's a new page. How would I make it so the name you chose on the first page also goes on to the page that load's on Fuzzy's.php?

Thanks, Liam
 
Session variables.

- on fuzzy.php start a new session or activate an existing session by calling session_start();

-create a session variable and assign your value (in this case, $_POST['name']) to the session variable
$_SESSION['sessionName'] = $_POST['name'];
Note the similarity between $_SESSION variables and $_POST variables.

It doesn't have to be sessionName. It can be whatever you want.

- on your "there is something you click which load's a new page." call the session again with session_start(); and then you can get your variable
echo $_SESSION['sessionName'];

I recommend you read more about it
http://www.w3schools.com/PHP/php_sessions.asp

Also, by fuzzy's.php you mean "the php script of fuzzy" and you really just mean fuzzy.php, for future questions just call it fuzzy.php
 
For the next page, you can use
echo $_REQUEST['name'];

Or better yet, store it in a session variable...
$_SESSION['name'] = $_REQUEST['name'];
echo $_SESSION['name']

Using the session variable, you can then move to another page, and still access the name by using...
echo $_SESSION['name']
 
Back
Top