Hello,

This string:
if (($POST['cartId'] == $POST['vcartId'])) && (strlen($POST['cartId']) == 14) && (is_numeric($POST['cartId']) ){

Is producing this error:
[10-Jul-2008 12:06:43] PHP Parse error: syntax error, unexpected T_BOOLEAN_AND in W:\www\FW15\sign-up-wizard\mobile-plan.php on line 76

Can anyone tell what is wrong with the above string?

Thank you!

    You're probably just missing a parens somewhere. You don't need to encase those statements in parens anyways. This works:

    if ($_POST['cartId'] == $_POST['vcartId'] && strlen($_POST['cartId']) == 14 && is_numeric($_POST['cartId']) ){

      enclose all of your expressions in parenthesis as a large group...

      // Nevermind...  Keep reading...
      //if ((($_POST['cartId'] == $_POST['vcartId'])) && (strlen($_POST['cartId']) == 14) && (is_numeric($_POST['cartId']) )){
      
      

      You just need to move your second closing paren to the end

      
      if (($_POST['cartId'] == $_POST['vcartId']) && (strlen($_POST['cartId']) == 14) && (is_numeric($_POST['cartId']) )){
      
      
        bretticus wrote:

        You don't need to encase those statements in parens anyways.

        Although this is true, I usually group my expressions in parens because I feel there is less chance for confusion because each statement is within it's own set of parens.

        Just my personal preference...

          Perfect, had an xtra ), that fixed everything, thank you.

          One other question if I may, I have one standard error message for this string -

          if (($_POST['cartId'] == $_POST['vcartId']) && (is_numeric($_POST['cartId'])) && (strlen($_POST['cartId']) >= 9) ){
                $_SESSION['cartId']=$_POST['cartId'];
          } else {
                $error_msg .= "Sorry, you appear to have entered an invalid phone number.<br />Possible reasons for this are:<br />1. Numbers provided did not match<br />2. Only numerical characters are allowed<br />3. You have not entered enough numbers to be a valid phone number.<br />Please try again." . "<br />";      
          }

          Would like to have seperate message based on the failed expression; any thoughts how I might accomplish?

          Thank you.

            As far as I know, you would have to test each case separately. Here is part of some code that I've used:

            $error_messages = array();
            if (/*TEST 1*/) {
                $error_messages[] = 'Error Message 1';
            }
            if (/*TEST 2*/) {
                $error_messages[] = 'Error Message 2';
            }
            if (/*TEST 3*/) {
                $error_messages[] = 'Error Message 3';
            }
            if (/*TEST 4*/) {
                $error_messages[] = 'Error Message 4';
            }
            if (!empty($error_messages)) {
                echo 'Please correct the following errors:';
                echo '<ul>';
                foreach ($error_messages as $error_message) {
                    echo '<li>';
                    echo $error_message;
                    echo '</li>';
                }
                echo '</ul>';
                exit();
            }
            

            If there is a better way for this, I would like to know; but this works for me.

              I usually make the errors array also. The only difference (from illzz example) is I like to use associative arrays so I can drop errors in the context of the page. For example:

              <?php
              $error_messages = array();
              if (/*TEST 1*/) {
                  $error_messages["phone"] = 'Error Message 1';
              }
              ?>
              <html>
              <body>
              <input type="text" name="phone">
              <?php echo $error_messages['phone'];?>
              </body>
              </html>

              EDIT

              I thought I better edit this to point out that the following code...

              <?php echo $error_messages['phone'];?>

              is for demonstrative purposes only. I realize that running that code without actually making an array element with that key will cause an invalid index warning.

                I ended up going with this, is a multi-page form so I store the errors message in a session and redirect them back to the page.

                if ($_POST['cartId'] == $_POST['vcartId']) {
                      $_SESSION['cartId']=$_POST['cartId'];
                } else {
                      $error_msg .= "Sorry, the phone numbers did not match, please try again" . "<br />";      
                } if (($_POST['cartId'] == $_POST['vcartId']) && (is_numeric($_POST['cartId'])) ){ $_SESSION['cartId']=$_POST['cartId']; } else { $error_msg .= "Sorry, your phone number must be all numerical characters<br />No \"-\" or \"()\" allowed, please try again " . "<br />";
                } if (($_POST['cartId'] == $_POST['vcartId']) && (strlen($_POST['cartId']) >= 9) ){ $_SESSION['cartId']=$_POST['cartId']; } else { $error_msg .= "Sorry, the phone number entered is not valid, please try again" . "<br />";
                }

                This runs my error message

                //Sends user back if required not filled
                if ( !empty($error_msg) ){
                      $_SESSION['error_prn']=$error_msg;
                      header("Location: mobile.php");
                }
                

                and this displays on page if error_msg is in session

                   		<?php
                 			if ( isset($_SESSION['error_prn']) && $_SESSION['error_prn'] )
                 			{
                   			echo "<pre class=\"alert\">{$_SESSION['error_prn']}</pre>";
                 			}
                		?>

                Works good. My only issue is when a user successfuly passes after erroring out the first time, the error message is still in session so if they don't complete the form and come back before the session expires they will see the error message again.

                  Write a Reply...