JonnyDevs
JonnyDevs

Reputation: 45

unable to call a method in a class from conditional statement

The issue is that for some odd reason my code to call a method is not calling the method, this method is locked(). Here is my class:

class login 
{
    public $username;
    public $password;
    public $fails;
    public $ip;
    public $sqlObject;


    public function sqlVerify() {
      $user=$this->username;
      $pass=$this->password;
      $sqlObject=$this->sqlObject;
      $fails=$this->fails;

      if($fails >= 4) { $this->locked(); }

      $query=mysqli_query($sqlObject, 
       "SELECT 1 FROM tbl_users 
        WHERE username='$user' AND password='$pass'");
       if(mysqli_num_rows($query) > 0){
           return "1";
       }else{
           return "0";
       }
    }

    private function locked() {
        return "For security, this account has been locked. Contact support.";
    }

}

the value of fails = 9 at this time, still no call.. ?

Upvotes: 0

Views: 36

Answers (1)

Jigar Pancholi
Jigar Pancholi

Reputation: 1249

Please try with below code:

public function sqlVerify() {
  $user=$this->username;
  $pass=$this->password;
  $sqlObject=$this->sqlObject;
  $fails=$this->fails;

  if($fails >= 4) { return $this->locked(); } // You need to put return statement here also for returning from this function.

  $query=mysqli_query($sqlObject, 
   "SELECT 1 FROM tbl_users 
    WHERE username='$user' AND password='$pass'");
   if(mysqli_num_rows($query) > 0){
       return "1";
   }else{
       return "0";
   }
}

private function locked() {
    return "For security, this account has been locked. Contact support.";
}

Upvotes: 3

Related Questions