Errors in mysqli, expected parameters

Asked

Viewed 225 times

0

The following errors are appearing:

Warning: mysqli_query() expects at least 2 Parameters, 1 Given in C: xampp htdocs rede profile.php on line 25

Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, null Given in C: xampp htdocs rede profile.php on line 26

Warning: mysqli_query() expects at least 2 Parameters, 1 Given in C: xampp htdocs rede profile.php on line 31

Warning: mysqli_error() expects Exactly 1 Parameter, 0 Given in C: xampp htdocs rede 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();
}
  • Wouldn’t have to call the connection here? $conf = mysqli_query($connect, $ins) or die(mysqli_error());

1 answer

0

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

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


Because that mistake?

The mysqli_query() function needs 2 mandatory parameter.

  1. The connection. Where you specify the mysql connection you will use.(In your case, the $connects variable you removed from the code by a previous error)
  2. A Query. Where you pass the command you will use in the database.

Tip:

When any error related to missing or over parameters, try to understand the function and understand which parameters it need to work. Removing variables because they generate error is not the correct if you do not know the purpose of the function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.