Re: isset not functioning

From: Date: Mon, 03 Aug 2009 17:23:09 +0000
Subject: Re: isset not functioning
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-296219@lists.php.net to get a copy of this message
> if(isset($_REQUEST['firstname']) && !empty($RESULT['firstname'])) { >  $name = $_REQUEST['firstname']; >  } else { >  $name = 'Sir or Madam'; > } > > Can anyone see any problems with the code? Your conditional will never evaluate to true. What is $RESULT? Where did it come from? $RESULT is not a built-in PHP variable or function, so empty($RESULT) will always be true, making !empty(...) always false. Also, it should be noted that if a form field exists, it will exist in the form data POSTed to PHP, even if the field is empty. I'm guessing that what you want to do is something like this: if(!empty($_POST['firstname']) { $name = $_POST['firstname']; } else { $name = 'Sir or Madam'; } empty() will evaluate to false if the field is empty OR if the field does not exist. Also not the use of $_POST instead of $_REQUEST. This will ensure that your data is actually coming from the form instead of an attacker trying to inject data with $_GET variables or some other source.

« previous php.general (#296219) next »