我正在尝试检查输入的电子邮件是否已注册到数据库中

时间:2016-10-24 04:48:25

标签: php mysqli

<?php 

include "includes/connection.php";

//function to insert user-information into users table.
function InsertUser(){
        global $conn;
        global $email;
    if(isset($_post['sign_up'])){

        $email = $_post['u_email'];
        $pass = $_post['u_pass'];
        $name = $_post['u_name'];
        $ph_no = $_post['u_ph_no'];
        $address = $_post['u_address'];
        $country = $_post['u_country'];
        $website = $_post['u_website'];
        $gender = $_post['u_gender'];
        $b_day = $_post['u_b_day'];
        $date = date(d-m-y);
        $status = "Unverified";
        $post = "NO";

    }

    $get_email = mysqli_query($conn, "SELECT user_email FROM users WHERE user_email = '$email'");
    $check_email = mysqli_num_rows($get_email);




}
?>

我收到了错误

  

警告:mysqli_query()要求参数1为mysqli,在第26行的/opt/lampp/htdocs/ioe_forum/functions/insert_user.php中给出null

     

警告:mysqli_num_rows()要求参数1为mysqli_result,在第27行的/opt/lampp/htdocs/ioe_forum/functions/insert_user.php中给出null

1 个答案:

答案 0 :(得分:0)

问题是您为[{1}}分配的全局变量,但您在$conn变量中创建了连接字符串。它只是变量错字错误。

$con

更改为

  $con = mysqli_connect($servername, $username, $password, $dbname);
 ^^^^^^

注意:这就是为什么mysqli_query由于连接null而执行失败的原因。

相关问题