Passing variables not working
Posted by: JimBobble (---.sip.owb.bellsouth.net)
Date: January 29, 2008 05:56AM

I'm sure this is a rookie question, but it has me stumped. I am passing variables via the URL in this fashion:

[localhost]

In the PHP, I check for the "type" value by doing the following:

if ($type == NULL) {
$type = "home";
}

The PHP code then uses the "type=" declaration to change the content based on the value. If the "type" variable is missing, it assumes "home."

My code is working fine on a "live" server, but locally on WAMP the variable is ignored. In other words, no matter what I put after the ? in the URL, I get the "home" content.

Is there some setting I'm missing in my WAMP PHP or Apache setup that allows variables to be passed in this fashion?

Thanks in advance!

Options: ReplyQuote
Re: Passing variables not working
Posted by: JimBobble (---.sip.owb.bellsouth.net)
Date: January 29, 2008 06:08AM

Well, folks, I have to apologize...I fixed it by using the $_GET function:

if ($_GET['type'] == NULL) {
$type = 'home';
} else {
$type = $_GET['type'];
}

It makes good sense why I should have been using it all along, but I'm still curious how the code worked on the hosted server. If anyone has an explanation I'd love to hear it!

Thanks again for the help.

Options: ReplyQuote
Re: Passing variables not working
Posted by: jw_k (---.net-you.de)
Date: January 29, 2008 01:41PM

to avoid php throwing errors like "index 'type' is not defined" better use:

if (empty($_GET['type'])) {
$type = 'home';
} else {
$type = $_GET['type'];
}

Options: ReplyQuote
Re: Passing variables not working
Posted by: rip_pit (---.w82-125.abo.wanadoo.fr)
Date: January 29, 2008 05:04PM

or shortly :
$type = ( !isset($_GET['type']) OR empty($_GET['type'])) ? 'home' : $_GET['type'] ;

---------------------------------------------
XP SP3 - pIV - 3.2Ghz - 1.5Go de ram - Wamp 2.0

Options: ReplyQuote


Sorry, only registered users may post in this forum.