MortHub MortHub - 6 months ago 11
HTML Question

Boolean PHP value is empty when being passed in URL. How do I retrieve it using $_GET[]?

I've been having a pretty dumb problem as of late.

I'm using the header function to redirect to a confirmation page. I'm declaring $error = false at the top of the php sendmail page.

Here is the conditional on the sendmail page:

if($error)
{
header('Location: http://www.url.com/confirmation.php
error='.$error.'type=cell&desc=' . $message);
}
else {
header('Location:http://www.url.com/confirmation.phperror='.$error.
'&type=cell&fname=' . $inputFName .'&lname=' . $inputLName . '&email=' .
$inputEmail . '&phnum=' . $inputPhnum . '&model=' . $inputModel .
'&color=' . $inputColor . '&desc=' . $inputSummary);
}


The problem I'm getting is, when I look at the URL and the get variables, the error portion is empty. For example, my url will look like: confirmation.php?error=&type=cell&fname=Test&lname=Name&email=test@test.com..... etc...

For some reason the error variable is NOT being passed. What's the problem?

Answer

You could pass another value as a "boolean", or simply use 1 / 0;

i.e

?....error=no

and then

if ($_GET["error"] === "no") {
    ...
} else {
    ...
}

or if you're going to use the number method, remember:

1 == true; 0 == false.

Comments