0

Does anyone have any idea as to why this is showing the error message? I have tired empty and boolean test.

Thanks!

<p>You have nearly a full tank of fuel at <?php echo $intFuelGallons ?> gallons.</p>
    <p> Do you want to top off your tank?
      <label>
        <input type="radio" name="TankTopOff" value="Yes" id="TankTopOff">
        Yes</label>
      <label>
        <input type="radio" name="TankTopOff" value="No" id="TankTopOff">
        No</label>
    </p>
    <p><?php echo $varWornTires ?> of your tires are worn. Do you want to replace any of them?</p>
    <label>
      <input type="radio" name="TireReplace" value="Yes" id="TireReplace">
      Yes</label>
    <label>
    <label>
      <input type="radio" name="TireReplace" value="No" id="TireReplace">
      No</label>
    <label>
 <?php
 if ((($_POST['TankTopOff'])!=="No") || (($_POST['TankTopOff'])!=="Yes")) {
 $errorMessage .= "<li><h5>You forgot to choose if you want to top off your tank! " . ($_POST['TankTopOff']) . "</h5></li>";
};
 if ((($_POST['TireReplace'])!=="No") || (($_POST['TireReplace'])!=="Yes")) {
 $errorMessage .= "<li><h5>You forgot to choose if you want to replace any tires! ". ($_POST['TireReplace']) . "</h5></li>";
};
?>
1
  • 1
    first of all, replace errorMessage with $errorMessage Commented May 3, 2013 at 11:36

3 Answers 3

3

The boolean expression will never be false:

(($_POST['TankTopOff'])!=="No") || (($_POST['TankTopOff'])!=="Yes")

translates as EITHER the TankTopOff is something else than "No" OR TankTopOff is something else than "Yes"; which is always true.

Probably you just need to replace || with && (or even better - "and", if as suggested by some PHP framework developers).

Sign up to request clarification or add additional context in comments.

1 Comment

Both worked but I liked empty as it was less complicated. I have no idea why it didn't work the first time... Might be too close to it!
1

Use

if(empty($_POST['TankTopOff']))

instead of

if ((($_POST['TankTopOff'])!=="No") || (($_POST['TankTopOff'])!=="Yes"))

and do the same with TireReplace

Comments

1

You should do

 <?php
   if ($_POST['TankTopOff']=='') {
        $errorMessage .= "<li><h5>You forgot to choose if you want to top off your tank! </h5></li>";
    };
   if ($_POST['TireReplace'])=='') {
        $errorMessage .= "<li><h5>You forgot to choose if you want to replace any tires!</h5></li>";
    };
  ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.