将值传递给类php [重复]

    <?php
class RegisterUser{
  var $email;
  var $password;
  var $password_hash;
  var $roleid;
  public function __construct($email, $password, $roleid){
    $this->email = $email;
    $this->password = $password;
    $this->roleid = $roleid;
    $this->addUsertoDB();
  }

  public function addUsertoDB(){
    $this->password_hash = md5($this->password);
    $checkemail = mysql_query("SELECT * FROM users WHERE (email ='" . mysql_real_escape_string($this->email) . "')");
    if(mysql_num_rows($checkemail) == 1){
      echo '<script type="text/javascript"> alert ("Email already used!");</script>';
    }
    else{
      $register = "INSERT INTO users(email, password, roleid) VALUES('$this->email', '$this->password_hash', '$this->$roleid')";
      if($query_run = mysql_query($register)){
        echo('<scrip type="text/javascript"> alert("Registration complete!"); location.replace("login")</script>');
      }
      else{
        die('<script type="text/javascript"> alert("Error inserting data!");</script>');
      }
    }
  }
}

$connect = new RegisterUser('carloadap@htomail.com', 123, 1);
?>

this is my code,I keep getting an error, i don't know how to figure it out. I hope you guys did.

this is the error.

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\myPHPWebsite\include\classRegister.php on line 17

Catchable fatal error: Object of class RegisterUser could not be converted to string in C:\xampp\htdocs\myPHPWebsite\include\classRegister.php on line 21

updated

    <?php
require 'connectDB.php';
class RegisterUser{
  var $email;
  var $password;
  var $password_hash;
  var $roleid;
  public function __construct($email, $password, $roleid){
    $this->email = $email;
    $this->password = $password;
    $this->roleid = $roleid;
    $this->addUsertoDB();
  }

  public function addUsertoDB(){
    $this->password_hash = md5($this->password);
    $checkemail = mysql_query("SELECT * FROM users WHERE (email ='" . mysql_real_escape_string($this->email) . "')");
    if(mysql_num_rows($checkemail) == 1){
      echo '<script type="text/javascript"> alert ("Email already used!");</script>';
    }
    else{
      $register = "INSERT INTO users(email, password, roleid) VALUES('$this->email', '$this->password_hash', '$this->$roleid')";
      if($query_run = mysql_query($register)){
        echo('<scrip type="text/javascript"> alert("Registration complete!"); location.replace("login")</script>');
      }
      else{
        die('<script type="text/javascript"> alert("Error inserting data!");</script>');
      }
    }
  }
}

$connect = new RegisterUser('carloadap@htomail.com', 123, 1);
?>

this is the error i get

Connected to Database! Catchable fatal error: Object of class RegisterUser could not be converted to string in C:\xampp\htdocs\myPHPWebsite\include\classRegister.php on line 22

</div>

The first error is caused by something being wrong in your MySQL. Try adding in
if($e = mysql_error()) die("MySQL error: ".$e); after the query.

That aside, your catchable fatal error is caused by $this->roleid being written as $this->$roleid by mistake. Also note that you are failing to escape strings on that line, so you're vulnerable to injections. It's not enough to only secure the first query, you have to do it every time ;)

form the error you given to us

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in
C:\xampp\htdocs\myPHPWebsite\include\classRegister.php on line 17

Seems like $checkmail value isn't valid mysql_num_rows() result. Check your query, and try to run it on your database console (phpmyadmin if you use that).

public function addUsertoDB(){
    ...
    $query = "SELECT * FROM users WHERE (email ='" . mysql_real_escape_string($this->email) . "')";
    checkemail = mysql_query($query) or die(mysql_errno() . " : " . mysql_error() . " : " . $query);
    ...