T_Hayden Posted June 9, 2006 Share Posted June 9, 2006 I am writing a validation for a simple form with validation. It takes the information and sends it to the validation page which either emails it or sends it back. I am getting an error after submitting the form.Parse error: parse error, unexpected T_BOOLEAN_OR in /home/www/baptistsermonhost/test/collegeform/collegeform.php on line 23Here is Line 23[code] if (empty($formVars['firstname'])) || (empty($formVars['lastname'])) || (empty($formVars['age'])) || (empty($formVars['line1'])) || (empty($formVars['city'])) || (empty($formVars['state'])) || (empty($formVars['areacode'])) || (empty($formVars['firstnumber'])) || (empty($formVars['secondnumber'])) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/ Share on other sites More sharing options...
.josh Posted June 9, 2006 Share Posted June 9, 2006 you are missing the closing ) for the whole thing Quote Link to comment https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43729 Share on other sites More sharing options...
poirot Posted June 9, 2006 Share Posted June 9, 2006 No, actually this error happens because he/she missed the first parenthesis.When it's added it, another error pops:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected '{' [/quote]Then he/she can close the whole thing [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]. Anyway, you don't need to use (empty($var)) || (empty($var2))... empty($var) || empty($var2) is enough.[code]if (empty($formVars['firstname']) || empty($formVars['lastname']) || empty($formVars['age']) || empty($formVars['line1']) || empty($formVars['city']) || empty($formVars['state']) || empty($formVars['areacode']) || empty($formVars['firstnumber']) || empty($formVars['secondnumber']))[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43734 Share on other sites More sharing options...
.josh Posted June 9, 2006 Share Posted June 9, 2006 okay so i missed the first one too. he needs to add ( ) around the whole darn thing. Quote Link to comment https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43747 Share on other sites More sharing options...
kenrbnsn Posted June 9, 2006 Share Posted June 9, 2006 I would advise against using "if (empty($fld))" to determine if something was entered into a field. If someone enters a zero, "0", in a field, the emtpy() function will return "true".Here's how I would do this:[code]<?php$err = false;foreach($_POST as $key=>$val) if (strlen(trim(stripslashes($val))) == 0) $err = true;if ($err) echo "One of the fields was left blank";?>[/code]You could get slightly fancier:[code]<?php$err = array();foreach($_POST as $key=>$val) if (strlen(trim(stripslashes($val))) == 0) $err[] = $key;if (!empty($err)) echo 'The following fields were left blank: ' . implode(', ',$err);?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43751 Share on other sites More sharing options...
.josh Posted June 9, 2006 Share Posted June 9, 2006 or you could simply do likeif ( !$formVars['age'] || !$formVars['name'] || ...) { .. } Quote Link to comment https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43755 Share on other sites More sharing options...
poirot Posted June 9, 2006 Share Posted June 9, 2006 Crayon, if you use that you will still have problems like0 is false" " (whitespace) is trueRefer to this table:[a href=\"http://www.php.net/manual/en/types.comparisons.php\" target=\"_blank\"]http://www.php.net/manual/en/types.comparisons.php[/a]I think ken's suggestion is appropriate. Quote Link to comment https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43758 Share on other sites More sharing options...
.josh Posted June 9, 2006 Share Posted June 9, 2006 okay so i'll just shut up now :\ Quote Link to comment https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43768 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.