为什么mysqli_num_rows没有返回值?

时间:2012-12-08 19:59:35

标签: php mysql

这是我网站的代码。它旨在注册新用户,只有登录的管理员才能执行此操作。该帐户已成功创建,但似乎没有为mysqli_num_rows返回1。我打印了num_rows返回的值,没有任何结果,甚至没有出现。我已经工作了好几天了,我对php编码很新,所以这可能是一个明显的错误,但我看不到它。任何帮助将不胜感激。我搜索过谷歌,但找不到任何东西。

if($_SERVER['REQUEST_METHOD']=="POST"){
    $name = mysqli_real_escape_string($_POST['fname']);
    $email = mysqli_real_escape_string($_POST['email']);
    $user = mysqli_real_escape_string($_POST['user']);
    $pass = mysqli_real_escape_string(md5($_POST['password']));
    $authority = mysqli_real_escape_string($_POST['use']);

    $queryCheck = "SELECT `user` FROM `user` WHERE `user`='$user';";
    $resultCheck = mysqli_query($link, $queryCheck);
    $rowCheck = mysqli_num_rows($resultCheck);
    if($rowCheck != 1){
    $query = "INSERT INTO `user` (`id`, `name`, `email`,`user`,`pass`) VALUES ($authority,'$name','$email','$user','$pass');";

    //echo $query;

    $result = mysqli_query($link, $query);
    $row = mysqli_affected_rows($result);

    if($row == 1){
        echo "User Created Successfully!<br/>";
        echo '<br/><br/><br/><a href="admin.php">Return to Administration Page</a>';

    }else{
        echo "User was not created, Please try again.";
    }
    }else{
        echo 'User already exists.';
    }
}

1 个答案:

答案 0 :(得分:0)

我发现你必须在mysql中使用mysqli_affected_rows作为插入短语。