Passing variables thru a URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Passing variables thru a URL

Post by Jim »

http://members.lycos.co.uk/jibfyb/

Select an item in the dropdown menu and you will see the URL change to "http://members.lycos.co.uk/jibfyb/index ... eryouchose".

Now, in that textarea box (which currently says '<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>'...) I have this code:

if($map == cat){ print("Hah!"); } else { print("<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>!"); }

So, choose cat in the dropdown menu.

The textarea box STILL says '<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>'.

How do I make sure $map is seen throughout the page as whatever has been selected in the drop box?

Thanks!
User avatar
amnuts
Forum Newbie
Posts: 16
Joined: Fri Jun 14, 2002 1:48 pm
Contact:

Re: Passing variables thru a URL

Post by amnuts »

Okay, this looks like your problem. You don't pass a query string like that. You need to start the query string with '?', and then just have the name of the variable (no $ sign.) Such as:

http://members.lycos.co.uk/jibfyb/index.php?map=cat

If you have global variables turned on you can then access it with $map in the script (once submitted), or with $_GET/$_POST, depending on the method of your form.

If you want more than one vairable you'd serperate up the variable/data pair with &, such as:

index.php?map=cat&name=scratch&colour=tan

Andy
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

and don't put " around the variable value

http://www.me.com/page.php?map=themapyouwant
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To access the map variable with register_globals turned off you'd use,

Code: Select all

$_GET&#1111;'map']
Mac
Post Reply