Errors in mysqli, expected parameters [duplicate]

0

The following errors are appearing:

  

Warning: mysqli_query () expects at least 2 parameters, 1 given in C: \ xampp \ htdocs \ network \ profile.php on line 25

     

Warning: mysqli_fetch_assoc () expects parameter 1 to be mysqli_result, null given in C: \ xampp \ htdocs \ network \ profile.php on line 26

     

Warning: mysqli_query () expects at least 2 parameters, 1 given in C: \ xampp \ htdocs \ network \ profile.php on line 31

     

Warning: mysqli_error () expects exactly 1 parameter, 0 given in C: \ xampp \ htdocs \ network \ profile.php on line 31

My code:

<?php
include("header.php");

$id = $_GET["id"];
$saberr = mysqli_query($connect, "SELECT * FROM users WHERE id='$id'");
$saber = mysqli_fetch_assoc($saberr);
$email = $saber["email"];

if ($email==$login_cookie) {
    header("Location: myprofile.php");
}

$pubs = mysqli_query($connect, "SELECT * FROM pubs WHERE user='$email' ORDER BY id desc");

if (isset($_POST['add'])) {
    add();
}

function add(){
    $login_cookie = $_COOKIE['login'];
    if (!isset($login_cookie)) {
        header("Location: login.php");
    }
    $id = $_GET['id'];
    $saberr = mysqli_query("SELECT * FROM users WHERE id='$id'");
    $saber = mysqli_fetch_assoc($saberr);
    $email = $saber['email'];
    $data = date("Y/m/d");

    $ins = "INSERT INTO amizades (de, para, data) VALUES ('$login_cookie', '$email', '$data')";
    $conf = mysqli_query($ins) or die(mysqli_error());
    if ($conf) {
        header("Location: profile.php?id=".$id);
    }else{
        echo "<h3>Erro ao enviar pedido...</h3>";
    }
}

if (isset($_POST['cancelar'])) {
    cancel();
}
    
asked by anonymous 06.11.2018 / 02:45

1 answer

0
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\rede\profile.php on line 25

That means that the function mysqli_query() expected 2 parameters and you only passed 1.

Why this error?

The mysqli_query () function needs 2 mandatory parameters.

  • The connection. Where you specify the mysql connection that will use. (In your case, the $ connect variable you removed from the code for a previous error)
  • The Query. Where do you pass the command that you will use in the database.
  • Tip:

      

    When there is an error related to lack or overflow of   parameters, try to understand the function and understand what parameters it   need to work. Removing variables because they generate error is not the   correct if you are unaware of the purpose of the function.

        
    06.11.2018 / 02:53