SilentQ-noob- Posted July 18, 2007 Share Posted July 18, 2007 Does anybody know how to make the PHP code for and if statement using strlen, where, if a field in a form isnt filled out an error message appears. so if the name field is empty it gives an error message. if (strlen($_POST['name'] <= 1 )) { echo "The Name field has not been filled out, or is too short"; include ("_form.php"); } else { echo " thanks for filling out our form" ; } this is what I have, doesnt work though....any help would be appreciated! thanks, -noob- Quote Link to comment Share on other sites More sharing options...
decypher Posted July 18, 2007 Share Posted July 18, 2007 add 'end if' might help Quote Link to comment Share on other sites More sharing options...
trq Posted July 18, 2007 Share Posted July 18, 2007 doesnt work though What does that mean? There is nothing inherently wrong with your code. Quote Link to comment Share on other sites More sharing options...
SilentQ-noob- Posted July 18, 2007 Author Share Posted July 18, 2007 still when I add that, and put something into the name field, it returns "The Name field has not been filled out, or is too short" Quote Link to comment Share on other sites More sharing options...
trq Posted July 18, 2007 Share Posted July 18, 2007 Sorry... must be half asleep. if (strlen($_POST['name']) <= 1 ) { Quote Link to comment Share on other sites More sharing options...
SilentQ-noob- Posted July 18, 2007 Author Share Posted July 18, 2007 if (strlen($_POST['name']) <= 1 ) { Thanks, but I've tried changing it to this, but that isnt the problem. The way I wrote it seems to be the correct syntax- (the way you suggested causes an error). So I really dont know why it returns true, regardless of wheather I put something into the name field or not. Quote Link to comment Share on other sites More sharing options...
trq Posted July 18, 2007 Share Posted July 18, 2007 The way I wrote it seems to be the correct syntax Well its not. strlen expects 1 string, not an expression. the way you suggested causes an error What error? Quote Link to comment Share on other sites More sharing options...
SilentQ-noob- Posted July 18, 2007 Author Share Posted July 18, 2007 sorry bro I just checked my code and there was an extra ' that I put in while typing it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.