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
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...

Edited by akphidelt2007
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.