Forums

This topic is locked

Sending variable from a php page to another

Posted 10 Mar 2008 22:48:42
1
has voted
10 Mar 2008 22:48:42 Chris Martin posted:
How do you send a variable from one PHP page to another? I am trying to accomplish this so that i can sort a MySQL database.

The page contains an image of the united states map with image links. Depending on what state the user clicks it will send the state code and the list will be determined off of that.

Thank You
Any help would be great!

Replies

Replied 11 Mar 2008 11:34:28
11 Mar 2008 11:34:28 Alan C replied:
HI Chirs,
there are a few different ways to handle this, depending on how secure you want it to be and how much trouble you want to go to.

An easy way is to tack the state code onto the url that you are calling for the next page, so you would have something like . . .

mydomain.co.uk/next_page.php?state_code=NY

the ? is a separator that tells php that there is something else coming, and you can add lots of paramters if you like by separating the name / value pairs with &

a quick search will turn up tutorials on this

once you do this the values are available in the $_GET array, so you can test that they have been set and then pick up the value - dangers

more trouble but better -

start a session in your first page, then put values into the session variables, again a quick search will turn up loads of information, basically, php keeps a record of everything you put into the session and it's available to the following pages. It all happens automatically once you have started the session and makes like much easier.

another way would be to put the state into a cookie

I would go with the parameter if there are no security risks as it's the easiest <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Reply to this topic