mysqli_num_rows错误,“期望参数1为资源”

时间:2013-10-11 03:02:03

标签: mysql mysql-num-rows

以下脚本返回错误: 警告:mysql_num_rows()期望参数1为资源

我无法弄清问题在哪里, 我测试了mysql连接,看起来很好, 我认为问题可能是$ result,但我找不到行中的错误。

我回应了$ reuslt并且它退缩了 可捕获的致命错误:类mysqli_result的对象无法转换为字符串


$link = mysqli_connect("127.0.0.1", "root", "")or die("cannot connect"); 
mysqli_select_db($link,"database")or die("cannot select DB");

    $name=$_POST['nameNews'];
    $email=$_POST['emailNews'];
    $name= mysqli_real_escape_string($link,$name);
    $email= mysqli_real_escape_string($link,$email);

if(isset($_POST['nameNews']) && isset($_POST['emailNews'])){

    $result=mysqli_query($link, "SELECT*FROM news WHERE email = '$email'");
    $numRows=mysqli_num_rows($result);

            if ($numRows==1)
            {echo"You have registered already.";}   
            else if ($numRows==0)
            {
            mysqli_query($link,"INSERT INTO news VALUES ($name,$email)");
            echo"Thankyou.";
            }
}

1 个答案:

答案 0 :(得分:0)

$result=mysqli_query("SELECT*FROM news WHERE email = '".$email."'");
$numRows=mysqli_num_rows($result);

检查这个