注意:未定义的变量:第243行的function.php中的conn致命错误:未捕获的错误:在null

时间:2019-06-02 08:15:51

标签: php

我正在编写此代码,但是我遇到了这个错误,我已经尝试了多种修复方法,但是我无济于事?

我希望它将html中的注册表单中的数据插入数据库并将我转换为个人资料页面

     --

function.php

class Users{

    // database connection and table name
    private $conn;
    private $table_name = "users";
    public $ID;
    public $firstName;
    public $lastName;
    public $email;
    public $user_type;
    public $password;
    // constructor with $db as database connection
    public function  __construct($conn){
        $this->conn = $conn;

    }

  function create(){ 
    // query to insert record
    $query = "INSERT INTO
                " . $this->table_name . "
            SET
                 firstName=:firstName ,lastName=:lastName, email=:email, password=:password, user_type=:user_type";

    // prepare query
    $stmt = $this->conn->prepare($query);

    // sanitize
    $this->firstName=htmlspecialchars(strip_tags($this->firstName));
    $this->lastName=htmlspecialchars(strip_tags($this->lastName));
    $this->email=htmlspecialchars(strip_tags($this->email));
    $this->password=htmlspecialchars(strip_tags($this->password));
    $this->user_type=htmlspecialchars(strip_tags($this->user_type));    
    $this->password=md5($this->password);
    // bind values
    $stmt->bindParam(":firstName", $this->firstName);
    $stmt->bindParam(":lastName", $this->lastName);

    $stmt->bindParam(":email", $this->email);
    $stmt->bindParam(":password", $this->password);
    $stmt->bindParam(":user_type", $this->user_type);


    // execute query
    if($stmt->execute()){
        return true;
        header('location:profile.php');
    }

    return false;

}
}

   if (isset($_REQUEST['register_btn'])) {
   $user = new Users($conn);
   $user->create();

}

0 个答案:

没有答案