niche Posted October 12, 2010 Share Posted October 12, 2010 While testing isset($_POST) as in:if (isset($_POST)) { echo 'here';}I keep seeing 'here' displayed when $_POST is empty.So, I ran:if (isset($_POST)) { echo var_dump($_POST);echo 'here';} ... and I see: here array(0) { } How can isset($_POST) be true when echo var_dump($_POST); = array(0) { } ? Link to comment Share on other sites More sharing options...
jeffman Posted October 12, 2010 Share Posted October 12, 2010 All isset is telling you is that the $_POST array exists. To test whether the array has content, you have to test individual elements, according to their names in the original form or POST string. Example: if your form has a text input with name="password", you need to do something like this:if (isset($_POST['password']) ) { // ... Link to comment Share on other sites More sharing options...
niche Posted October 12, 2010 Author Share Posted October 12, 2010 changed isset($_POST) to count($_POST) > 0 as in:if (count($_POST) > 0) {echo var_dump($_POST);echo 'here';} Thanks Deirdre's Dad. Link to comment Share on other sites More sharing options...
ShadowMage Posted October 12, 2010 Share Posted October 12, 2010 FWIW, you can also use the empty() function to check if a value exists and has a non-empty value. See the manual page for values that are considered empty. Link to comment Share on other sites More sharing options...
niche Posted October 12, 2010 Author Share Posted October 12, 2010 Great follow-up.Thanks ShadowMage, Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.