Error Mysqli mysqli_query () expects parameter 1 to be mysqli, even if I am already giving you the two parameters that you request [duplicated]


I have this code:

    require ("../clases/Conexion.php");

         $host = "localhost:3307";
         $user = "root";
         $pass = "";
         $bd = "nutricion";
         $con = mysqli_connect($host,$user,$pass,$bd) or die("Error al conectar al Servidor");
         $con = new conexion();

    if ($_SESSION["correo"]=='') {
        //header("Location:../index.php");  exit;
        echo "1";
    $msql_db_query= mysqli_query($bd,"SELECT * FROM tbl_usuario WHERE correo='" . $_SESSION['correo'] . "';") or die ("Error al buscar usuario");
    if ($result) {
        $id_usuario = mysqli_result($msql_db_query(),0,'id');
        $nombre_usuario = mysqli_result($msql_db_query(),0,'nombre') . " " . mysqli_result($msql_db_query(),0,'apellido');
     }else {
        //header("Location:../index.php");  exit;
        echo "2";


Which generates the following error:


Warning: mysqli_query () expects parameter 1 to be mysqli, object given in C: \ xampp \ htdocs \ admin \ classes \ Access.php on line 17   Error searching for user

I searched the internet for the solution but I can not find it, I wanted to see if anyone could help me by verifying my code. It is assumed that after going through the login should go to another page, before it worked, but now no longer.

Try all the sufferings that were made to me, the ones I found on the internet and nothing works for me, I do not understand why I get that error if I'm really giving you the 2 parameters that you ask me for.

asked by Analy 18.04.2018 в 19:52

2 answers


Welcome, Analy. The error tells you that the function mysqli_query expects that in the first parameter you place the connection object to your database, and you are sending it the name of the database.

In your code, you need to store in some variable the action you do to connect, which is surely in $con->conectar(); .

I suggest you change to something like this, and tell us if it served you:

$link = $con->conectar();

$msql_db_query= mysqli_query($link, "SELECT * FROM tbl_usuario WHERE correo='" . $_SESSION['correo'] . "';") or die ("Error al buscar usuario");
answered by 18.04.2018 в 20:01


Inside your SQL query, you must first pass the connection variable, not the variable that has the name of your database

It should look like this

$msql_db_query= mysqli_query($con,"SELECT * FROM tbl_usuario WHERE correo='" . $_SESSION['correo'] . "';") 
or die ("Error al buscar usuario");

Another thing I think you use POO at the moment of doing the following:

 $con = new conexion();

If you do the above, you do not have to redeclare the complete connection   because you're supposed to have already done it in the file called   Conexion.php; check that


Delete the connection you have repeated in your file that shows   since the logic you have already comes from the Connection file

answered by 18.04.2018 в 20:00