PHP OOP MySQL注册系统MySQL\u NUM\u行错误
好吧,我的注册是有效的,除了检测用户是否已经创建的代码不起作用之外PHP OOP MySQL注册系统MySQL\u NUM\u行错误,php,mysql,oop,Php,Mysql,Oop,好吧,我的注册是有效的,除了检测用户是否已经创建的代码不起作用之外 public function register($username, $password) { global $core, $db; $username = $core->encrypt($username); $password = $core->encrypt($password); $qry = $db->query("SELECT *
public function register($username, $password) {
global $core, $db;
$username = $core->encrypt($username);
$password = $core->encrypt($password);
$qry = $db->query("SELECT *
FROM `users`
WHERE `username` = '$username'
AND `password` = '$password'");
$num = $db->num($qry);
if($num >= 1) {
echo 'This username has already been registered';
} else {
$db->query("INSERT INTO `users`
(username, password)
VALUES
('{$username}', '{$password}');");
}
}
这是我使用的代码,我认为这是查询中的某种形式的错误,但我不确定是什么-可能是一个小错误
MySQL错误:
>Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\housekeeping\_inc\db.inc.php on line 14
>$db->num code
public function num($query) {
mysql_num_rows($query); << line 14
}
>警告:mysql_num_rows()希望参数1是resource,在第14行的C:\xampp\htdocs\housing\\u inc\db.inc.php中给出空值
>$db->num代码
公共函数num($query){
mysql_num_rows($query);您忘记了num函数和qry函数中的return语句。它应该是:
public function num($query) {
return mysql_num_rows($query);
}
您没有提供qry函数的代码,但应该是这样的:
public function qry($sql) {
return mysql_query($sql);
}
您确定$db->query会返回结果(而不是true/false)。在函数内部,在全局变量之后,尝试“print_r($db);”并查看结果