Jump to content

Archived

This topic is now archived and is closed to further replies.

T_Hayden

T_BOOLEAN_OR error

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]

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.