Jump to content

isset($_POST['message']) vs $_POST['message']!=''


Q695

Recommended Posts

How are these not saying to check for the same thing, because when I run the isset it's thinking $_POST['message']! that a blank entry is something there, but !='' is saying that a blank entry isn't there?  I tried the isset a few times, but every time it came out allowing a blank message the same way.

 

Is that a bug with WAMP:Apache Version :2.2.17/PHP Version :5.3.4?

Link to comment
https://forums.phpfreaks.com/topic/277735-isset_postmessage-vs-_postmessage/
Share on other sites

No, it's per the documentation. Isset simply checks to see if the key/variable exists regardless of the value. You can use...

if(isset($_POST['message']) && !$_POST['message'])

This would indicate the key/variable exists but the value is empty, blank, 0, false, etc...

all text and textarea form fields are set any time the form is submitted, even if they are empty. only checkbox/radiobuttons will not be set when they are not selected.

 

what makes you think your variable from a form will/should be a null?

 

your form processing code should test if a form has been submitted, then all the code within the form processing code doesn't need to individually test if text/textarea fields are set. they will be.

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.