致命错误:未捕获错误:在C:\ xampp \ htdocs \ project \ class.php:16中调用null成员函数query()堆栈跟踪:#0 C:\ xampp \ htdocs \ project \ register。 php(6):reg-> registration('SAFDFD','fcec3612a0103be ...','ASF@DGGG.H')#1 {main}在C:\ xampp \ htdocs \ project \ class.php中抛出16
我是初学者。请输入您关于此错误的信息。
register.php
include "class.php";
$user = new reg();
if (isset($_POST['submit'])){
extract($_POST);
$register = $user->registration($uname,$password,$email);
if($register){
echo "added";
}else{
echo "error";
}
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="" method="post">
User Name:<input type="text" name="uname">
Password: <input type="password" name="password">
Email:<input type="email" name="email">
<button name="submit">submit</button>
</form>
</body>
</html>
class.php
include ('db.php');
class reg{
protected $db;
function __construct(){
$this->db = new db_connect();
$this->db = $this->db->return_obj();
}
public function registration($uname,$password,$email){
$password = md5($password);
$query = "SELECT * from user where username = '$uname' OR email ='$email'";
$result = $this->db->query($query) or die($this->db->error);
$count = $result->num_rows;
if ($count ==0){
$query ="INSERT into user where username = '$uname' and email = '$email' and password='$password'";
$result =$this->db->query($query) or die ($this->db->error);
return true;
}else{
return false;
}