Problem with an array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Latio

    Problem with an array

    I have the following line:

    if($newValidate->isNotEmpty($th is->userName) &&
    $newValidate->isNotEmpty($th is->passWord))

    which checks to see if two text boxes contain any data. However if both
    boxes are empty, it only displays the error message once. Below is the
    Validate class.

    <?php

    class Validate
    {
    private $valueToCheck;
    private $errorMessage;

    function printErrorMessa ge ()
    {
    print $this->errorMessage[0];
    print $this->errorMessage[1];
    }

    function isNotEmpty($val ueToCheck)
    {
    if (!empty($valueT oCheck))
    {
    return TRUE;
    }
    else
    {
    $message = "A field is empty.";
    $this->errorMessage[] = $message;
    return FALSE;
    }
    }
    }
    ?>


  • Rik

    #2
    Re: Problem with an array

    Phil Latio wrote:
    I have the following line:
    >
    if($newValidate->isNotEmpty($th is->userName) &&
    $newValidate->isNotEmpty($th is->passWord))
    >
    which checks to see if two text boxes contain any data. However if
    both boxes are empty, it only displays the error message once. Below
    is the Validate class.
    If the first statement evaluates to false, the other statement won't be
    checked.
    Try something along the lines of:
    if($newValidate->isEmpty($thi s->userName) ||
    !$newValidate->isEmpty($thi s->passWord))


    --
    Rik Wasmus


    Comment

    • Phil Latio

      #3
      Re: Problem with an array

      If the first statement evaluates to false, the other statement won't be
      checked.
      Try something along the lines of:
      if($newValidate->isEmpty($thi s->userName) ||
      !$newValidate->isEmpty($thi s->passWord))
      >
      >
      --
      Rik Wasmus
      I replaced && with || and it worked !!!

      Many thanks for the quick reply. I would have taken some time to work out it
      was the use of && in the statement that was causing the problem.

      Cheers

      Phil


      Comment

      Working...