【问题标题】:Warning: mysql_query() expects parameter 1 to be string, object given in C:\xampp\htdocs\social_network\functions\functions.php on line 20 [duplicate]警告:mysql_query() 期望参数 1 是字符串,在第 20 行的 C:\xampp\htdocs\social_network\functions\functions.php 中给出的对象 [重复]
【发布时间】:2016-09-24 14:11:00
【问题描述】:

错误:

警告:mysql_query() 期望参数 1 是字符串,对象在 C:\xampp\htdocs\social_network\functions\functions.php 第 20 行给出

警告:mysql_num_rows() 期望参数 1 是资源,在第 21 行的 C:\xampp\htdocs\social_network\functions\functions.php 中给出 null

我正在使用 连接

$con = mysqli_connect("localhost","root","","social_network") 或 die("连接未建立");

代码:

function InsertUser(){
    global $con;
if(isset ($_POST['sign_up'])){

    $name = $_POST['u_name'];
    $psss = $_POST['u_pass'];
    $email = $_POST['u_email'];
    $country = $_POST['u_country'];
    $gender = $_POST['u_gender'];
    $b_day = $_POST['u_birthday'];
    $name = $_POST['u_name'];
    $date = date("d-m-y");
    $status = "unverified";
    $posts = "No";

    $get_email = "select * from users where user_email='$email'";
    $run_email = mysql_query($con,$get_email);
    $check = mysql_num_rows($run_email);

    if($check==1){

        echo "<script>alert ('Email is already registered, please try another one!')</script>";
        exit();
    }

}
}

?>

【问题讨论】:

  • 你需要调试你的代码。 1. var_dump($con) 在你的函数中检查你得到的值。 2.使用mysql_error()函数>>$run_email = mysql_query($con,$get_email); or die(mysql_error())
  • 不知道您使用哪个 API 进行连接。
  • $con = mysqli_connect("localhost","root","","social_network") 或 die("连接未建立");
  • 请务必花时间阅读有关给定 MySQL API 的手册。您对“ADHD 和阅读障碍” 的看法简直是垃圾。不久前我也看到过同样的帖子。多动症和阅读障碍不是借口。我也有阅读障碍的案例(事实),这从未阻止我使用正确的语法。

标签: php


【解决方案1】:
$run_email = mysql_query($get_email,$con);

仅供参考 mysql 驱动程序已被弃用,您必须使用 mysqli 或 PDO。

【讨论】:

  • 当然,如果他们使用 MySQL_ API 进行连接,我们不确定。
  • 她写的是mysql语句,不是mysqli或pdo语句,所以肯定是用了mysql驱动。
  • 您的语法对于使用 MySQL_ API 是正确的,但是关于 OP 用于连接的内容的真相终于浮出水面(在编辑和附加评论中)。我分别关闭了这个问题。
  • 是的,你是对的,周末快乐,干杯!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-28
  • 2016-07-14
相关资源
最近更新 更多