PHP GET and variables

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP GET and variables

Postby eliter4v3n » 23. October 2006 19:21

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
eliter4v3n
 
Posts: 4
Joined: 18. October 2005 15:28

Postby Wiedmann » 23. October 2006 20:19

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.
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: PHP GET and variables

Postby ldivinag » 26. October 2006 04:35

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...
leo d.
User avatar
ldivinag
 
Posts: 40
Joined: 19. April 2006 04:18


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 53 guests