我正在尝试将用户保存到数据库中,除了一个问题外,一切似乎都没问题
为什么每次我尝试调用save_user(...)我都会
Fatal error: Call to undefined function check_user() in ... on line 47
连接课程:
class Db_connect {
function __construct(){
}
function __destruct(){
}
function connect(){
$connect = MySQL_Connect ( "host", "user", "pass") or Die("Couldn't connect to DB");
MySQL_Select_Db("db") or Die("Couldn't find database db");
mysql_query("SET NAMES 'utf-8'");
return $conect;
}
function close(){
MySQL_close();
}
}
函数类
class Db_functions {
private $db;
function __construct(){
$this->db = new Db_connect();
$this->db->connect();
}
function __destruct(){
}
public function check_user($email,$pass){
$result = "SELECT email FROM user WHERE email='$email' AND pass='$pass'";
$sql = mysql_query($result);
if ( mysql_num_rows($sql) > 0 ) {
return true;
}
return false;
}
public function save_user($id,$name,$pass,$email,$country){
$result = "INSERT INTO user(id,name,pass,email,country) VALUES('$id','$name','$pass','$email','$country')";
if ( check_user($email,$pass) ) { //here's line 47
return false;
}
if ( mysql_query($result) ) {
return true;
}
return false;
}
}
我真的很累:D我找不到任何错误
答案 0 :(得分:2)
您正在以
的身份访问该类成员if ( check_user($email,$pass) ) {
这是不正确的,你需要做
if ( $this->check_user($email,$pass) ) {
这需要在您的代码中进行更正。