Page 1 of 1

PHP GET and variables

PostPosted: 23. October 2006 19:21
by eliter4v3n
In the latest version of XAMPP i can not get any variables to work when they are either GET or just stated in the URL.

an example would be
Code: Select all
<?php
echo("$id");
?>


Then when i would do: "http://localhost/test.php?id=1" it comes up blank. Now if i do this on my actual WEBserver it works fine.

Anyone have any idea why this would not work? It worked fine with previous versions of XAMPP i belive!

Thanks alot for any help.
-Jon

PostPosted: 23. October 2006 20:19
by Wiedmann
Anyone have any idea why this would not work?

Sure, that's wrong ;-)

Add a "error_reporting(E_ALL);" at the top of the script, and you can see that the variable "$id" is unknown.

You should also read the PHP manual about "external variables".

BTW:
"$_GET['id']" is correct.

Re: PHP GET and variables

PostPosted: 26. October 2006 04:35
by ldivinag
eliter4v3n wrote:In the latest version of XAMPP i can not get any variables to work when they are either GET or just stated in the URL.

an example would be
Code: Select all
<?php
echo("$id");
?>


Then when i would do: "http://localhost/test.php?id=1" it comes up blank. Now if i do this on my actual WEBserver it works fine.

Anyone have any idea why this would not work? It worked fine with previous versions of XAMPP i belive!

Thanks alot for any help.
-Jon



since you are passing it via the URL, you can use the the super global variable array $_GET

so in this case:

Code: Select all
echo ($_GET["id"]);


note that no "$" is needed inside the brackets since, the $_GET is an array...

Code: Select all
http://localhost/test.php?id=1&id2=2


would be accessed like:

Code: Select all
echo ($_GET["id"]);
echo ($_GET["id2"]);



if you are processing a FORM with an POST, you just use the $_POST super global instead...

personally, whenever i need to access any super global variable, i like to assign them local (in scope-wise) variable for easier access...