Hướng dẫn uncaught valueerror mysqli_query argument 2 query cannot be empty - uncaught valueerror truy vấn đối số mysqli_query 2 không được để trống

Tôi đã nhận được 4 lỗi trong khi chạy mã này thêm địa chỉ email của người dùng vào cơ sở dữ liệu có tên ecommerce trong bảng có tên là subscriptions.

$ con = new mysqli ('localhost', 'root', '', 'thương mại điện tử');

if (!$con) {
    die('Could not connect: ' . mysql_error());
}    

$errors = array();
if($_POST)
    {
        if(empty($_POST['email']))
        {
            $errors['email1'] = "

Dont forget to write your email!

"; }else { $email = test_input($_POST["email"]); // check if e-mail address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors['email2'] = "

Something wrong is with your email

"; }else{ // check if the email already exists $query = mysqli_query("SELECT * FROM subscriptions WHERE email='$email'"); if(mysqli_num_rows($query) > 0){ $errors['email3'] = "

Your had been registered before!

"; } } } //check errors if(count($errors) == 0) { $insert_email = mysqli_query("INSERT INTO subscriptions (email) VALUES ('$email')"); $insert_email = mysqli_query($con, $insert_email); $success = ""; } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>

You can add your email to our emailsshow list.

";}?>

Các lỗi như thế này:

Cảnh báo: mysqli_query () mong đợi ít nhất 2 tham số, 1 được đưa ra trên dòng 27

Dòng 27:

$ query = mysqli_query ("Chọn * từ các đăng ký trong đó email = '$ email'");

Cảnh báo: mysqli_num_rows () mong đợi tham số 1 sẽ là mysqli_result, null được đưa ra trên dòng 28

Dòng 28:

if (mysqli_num_rows ($ query)> 0) {

Cảnh báo: mysqli_query () mong đợi ít nhất 2 tham số, 1 được đưa ra trên dòng 37

Dòng 37:

$ insert_email = mysqli_query ("chèn vào các giá trị đăng ký (email) ('$ email')");

Cảnh báo: mysqli_query (): Truy vấn trống trên dòng 38

Dòng 38:

$ insert_email = mysqli_query ($ con, $ insert_email);

Tôi là người mới ở diễn đàn này và tốt nhất là bạn có thể giúp tôi với điều đó vì tôi thực sự biết phải làm ... Cảm ơn trước!

Điều gì xảy ra với $query khi $_SESSION['user_role'] không '1' hay '0'?

if($_SESSION['user_role']=='1'){

$query="SELECT post.post_id, post.title, post.description, post.post_date, category.category_name,user.username FROM post
LEFT JOIN category ON post.category = category.category_id
LEFT JOIN user ON post.author = user.user_id
ORDER BY post.post_id DESC LIMIT {$offset},{$limit}";

}elseif ($_SESSION['user_role']=='0')
   {
    $query ="SELECT post.post_id, post.title, post.description, post.post_date, category.category_name, user.username FROM post
    LEFT JOIN category ON post.category = category.category_id
    LEFT JOIN user ON post.author = user.user_id
    WHERE post.author = {$_SESSION['user_id']}
    ORDER BY post.post_id DESC LIMIT {$offset},{$limit} ";

   }

 #data show and pagination
 $result= mysqli_query($connection,$query) or die(mysqli_error($result));