I am currently writing a isRegistered function. This function is written within a class called User. This is the code:

public function isRegistered($email){
        $ir =   $this->db->prepare('select * from users where email=?');
        $ir->bindParam(1, $email);
        $ir->execute();
        if ($ir->rowCount()==1){
            return true;
        }
        else { return false;}
}//end of function isRegistered 

I am instantiating the class and this function on the register page, and I am trying to do this:

    if(!empty($_POST['email'])){
        $email  =   $_POST['email'];
        $fp =   new User();
        $fp->isRegistered($email);
        if($fp==1){
        echo "email exists";    
        }
        else {echo "email doesn't exist.";}
    }
    else echo "Please enter an email address.";

Obviously this is not working. How do I get it to work? What is the right way to do it? I know I am returning either a true or a false from the method isRegistered. I just don't know how to pick that response up when I instantiate it.

有帮助吗?

解决方案

I think you want:

if($fp->isRegistered($email)){
   ...

Or assign the return value of your function to $fp...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top