Jump to content

$variable not empty?


Startses

Recommended Posts

I have a function that checks wether the form submitted an empty field or not, basically goes like this:

 

index.php___________

 

check($_POST['formfield'])

 

 

 

 

functions.php___________

function check($text){
if (empty($text))
return false;
else
return true;

}

 

but it ALWAYS returns true, as if there is something stored within the variable.

is there something invisible to be erased from the $_POST variable so it can be empty?

Link to comment
https://forums.phpfreaks.com/topic/169830-variable-not-empty/
Share on other sites

Use isset() and remove your redundant function. The functionality you want is provided by isset().

empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set.  Return Values Returns FALSE if var has a non-empty and non-zero value.

The following things are considered to be empty: 

  • "" (an empty string)  0 (0 as an integer)  "0" (0 as a string)  NULL  FALSE  array() (an empty array)  var $var; (a variable declared, but without a value in a class)

Link to comment
https://forums.phpfreaks.com/topic/169830-variable-not-empty/#findComment-895972
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.