Page 1 of 1

Passing variables

Posted: Thu May 15, 2003 1:49 pm
by mikusan
Could someone take the time to explain to me how to pass variables from file to file *.php

you know how when you click on a specific link... the request is sent in the header in the form... sitename.com/index.php?something=23&fields=true...

how to make those but most importantly how to retrieve them...

thx abunch

Posted: Thu May 15, 2003 1:57 pm
by mikusan
I read the post above... but thought this didn;t quite apply or perhaps i didn;t understand the other one clearly enough

Posted: Thu May 15, 2003 2:02 pm
by Jim
To get information that is passed along in a query string, use the $_GET global.

For instance, in a string like:

http://www.yoursite.com/index.php?monkey=Bob&cat=Tom

where Bob defines the variable monkey and Tom defines the variable cat, you would use:

Code: Select all

$_GET['monkey'];  // This would translate to the value "Bob."
$_GET['cat']; //This would in turn translate to the value "Tom."
To create query strings, simply use the normal URL format followed by a "?" (question mark symbol). For every variable you list after the first one, you the "&" (ampersand symbol) to denote separations.

Note that you can set the values for variables as variables themselves.

For instance, in the original string, if you want to set the value of 'monkey' as the variable '$monkeyname' and the value of the variable 'cat' as '$catname', do the following (assuming you already have these variables set in your script):

http://www.yoursite.com/index.php?monke ... t=$catname

Very simple stuff! Enjoy!