PHP警告:mysql_num_rows()期望参数1为资源,在第32行的/home/mattahu/public_html/register.php中给出null

时间:2018-05-05 02:19:26

标签: php mysql

我正在努力为此错误消息找到任何解决方案。请帮忙

  

PHP警告:mysql_num_rows()期望参数1为资源,在第32行的/home/mattahu/public_html/register.php中给出null

代码:

if(isset($_POST['username'])) {
    //variables for sign
    $username = $_POST['username'];
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $email = $_POST['email'];
    $pass1 = $_POST['pass1'];
    $pass2 = $_POST['pass2'];

    //errors
    if((!$username)||(!$fname)||(!$lname)||(!$email)||(!$pass1)||(!$pass2)){
        $message ='Please enter all the detail fields'; //not entered all fields
    }
    else 
    {
        if($pass1 != $pass2) {
            $message ='Your passwords do not match';    
        }
        else {
            //what can be entered
            $username = preg_replace('#[^0-9a-z]#i',"",$username);
            $fname = preg_replace('#[^0-9a-z]#i',"",$fname);
            $lname = preg_replace('#[^0-9a-z]#i',"",$lname);
            $pass1 = sha1($pass1);

            $email = mysql_real_escape_string($email);

            //make sure there isn't doubles
            $user_query= mysql_query("SELECT username FROM Members WHERE username='$username'LIMIT 1") or die('Could not check username');
            $count_username= mysql_num_rows($username_query);

            $user_query= mysql_query("SELECT email FROM Members WHERE email='$email'LIMIT 1") or die('Could not check username');
            $count_email= mysql_num_rows($email_query);

            if($count_username > 0) {
                $message = 'Your username is already taken';
            } else if($count_email > 0) {
                $message = 'Email already in use';
            } else {
                //insert members
                $ip_address=$_SERVER['REMOTE_ADDR'];
                $query = mysql_query("INSERT INTO Members (username, firstname, lastname, email, password, ip_address, sign_up_date) VALUES ('$username','$fname','$lname','$email','$pass1','$ip_address',now())") or die("Could not insert your information");

1 个答案:

答案 0 :(得分:0)

您尝试使用" $ username_query" 但实际变量为" $ user_query" 。 同样对于下一个查询,您再次声明$ user_query并尝试在以下mysql_num_rows函数中使用" $ email_query"