【问题标题】:Errors while submitting data to the server using form使用表单向服务器提交数据时出错
【发布时间】:2014-10-18 10:22:34
【问题描述】:

我正在尝试通过表单提交数据并遇到以下错误:

警告:mysql_num_rows() 期望参数 1 是资源,给定布尔值 ..

请找到我尝试过的代码。

//connection end to my data server.

if(isset($_POST["submit"])) {

     $user_name = $_POST['name'];
     $user_email = $_POST['email'];
     $user_skype = $_POST['skype'];

    if($user_name==""){
        echo "<script>alert('please enter your user name!')</script>";
        exit();
    }

    if($user_email==""){
        echo "<script>alert('please enter your email!')</script>";
        exit();
    }       

    if($user_skype==""){
        echo "<script>alert('please enter your skype id.')</script>";
        exit();
    }   

    $check_email = "select * from binary where user_email = '$user_email' ";

    $run = mysql_query($check_email);

    if(mysql_num_rows($run)>0){

    echo "<script>alert('Your email $user_email address already exist. please try another.')</script>";
    exit();

    }

    $query= "insert into binary (user_name, user_email, user_skype) values('$user_name','$user_email','$user_skype')";

    if(mysql_query($query)){
    echo "<script>window.open('success.html','_self')</script>";
    }

}

?>

【问题讨论】:

  • 请详细解释一下我是 php 新手.. :(
  • 首先,考虑放弃已弃用的mysql_* 函数并改用MySQLi 之类的东西:它更安全。 php.net/manual/en/book.mysqli.php

标签: php registration subscriber


【解决方案1】:

二进制是sql reserrve word

在它周围使用 反引号

$check_email = "select * from `binary` where user_email = '$user_email' ";

检查此链接以获取 sql 保留字。 http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

并学习 mysqli_ 功能或 P.D.O 因为 mysql 已被废弃

【讨论】:

    【解决方案2】:

    请更新您的查询: 应该是

    $check_email = "select * from `binary` where user_email = '".$user_email."' ";
    

    【讨论】:

      【解决方案3】:

      似乎 select 查询返回 boolean false 因为

      $check_email = "select * from binary where user_email = '$user_email' "
      

      其中 user_email = '$user_email' 无法解析 '$user_email' 的值,因为单个 quat 中的变量无法使用它们的值进行解析

      使用:- 其中 user_email = ".$user_email; 一切都应该正常

      【讨论】:

        猜你喜欢
        • 2015-08-28
        • 2021-03-31
        • 2012-07-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-16
        • 2013-03-17
        • 2015-02-12
        相关资源
        最近更新 更多