DMort
DMort

Reputation: 347

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 protected]..... etc...

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

Upvotes: 0

Views: 475

Answers (2)

Ankit Gupta
Ankit Gupta

Reputation: 175

From http://php.net/manual/en/language.types.string.php:

A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values.

So you can either do the following or what @Tobi suggested to achieve it:

$errorStr = $error ? 'true': 'false';

Upvotes: 0

user4584267
user4584267

Reputation:

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.

Upvotes: 2

Related Questions