Jump to content

Recommended Posts

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 23

Here 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]
Link to comment
https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43734
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43751
Share on other sites

Crayon, if you use that you will still have problems like

0 is false
" " (whitespace) is true

Refer 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.
Link to comment
https://forums.phpfreaks.com/topic/11592-t_boolean_or-error/#findComment-43758
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.