View Full Version : write forn value

02-24-2004, 07:57 PM
I was wondering if it is possible to write a form variable from the url bar?

My basic script is:
if ($_POST["name"] == 1)
echo "you typed mike";
elseif ($_POST["name"] == 2)
echo "you typed 2";
echo "wrong";

And i want to set the 'name' value with the URL in the address bar.
Is it possible
Thanks for any help

02-24-2004, 08:04 PM
If it's from the url, you should probably use $_GET instead of $_POST.

If you'd like to cycle through all the variables in the url, I think you can do something like:

foreach($_GET as $var => $val) {
echo $var."=".$val."<br>";

Hope that helps,

02-24-2004, 08:54 PM
thanks for that as it was useful for something else but i didn't explain very well,

i want to set the 'name' value from the url bar eg


the above is just an example but is there a way to do this?


02-24-2004, 09:04 PM
I think it has something to do with some of your PHP settings, like $GLOBALS on or something... check your php.ini

If you have GLOBALS as on, then you can reference it as $name, and you don't have to set any values.

I'm pretty sure using $_GET["name"] would do the same thing though.. anyone feel free to correct me if I'm wrong.

So just to re-write that, if you've got your GLOBALS on then you can start referencing $name without declaring it or anything if it's in the url like you've specified.

I think you can also use $_GET["name"] to get its value. I think there are some security issues with accepting variables from the url, but if you're not building an application where security is an issue then I don't think it should be a problem.

Hope that helps,

02-24-2004, 09:08 PM
Thanks alot for your help

Ive now sorted it.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum