Warring: mysqli_query () expects parameter 2 to be string, object given in

-1

I leave the code so you can help me:

 <?php
session_start();
include ('Connections/conexion2.php');

$arreglo=$_SESSION['carrito'];

    $numeroventa=0;
    $re=mysqli_query($con, "SELECT * from compras order by numeroventa DESC limit 1") or die(mysqli_error($con)); 
     $query=mysqli_query($con,$re);
            while ($f=mysqli_fetch_array($con, MYSQLI_ASSOC)) {
          $numeroventa=$f['numeroventa']; 
    }
    if($numeroventa==0){
      $numeroventa=1;
    }else{
      $numeroventa=$numeroventa+1;
    }
    for($i=0; $i<count($arreglo);$i++){
      mysqli_query("UPDATE compras SET (numeroventa, imagen,nombre,precio,cantidad,subtotal) values(
        ".$numeroventa.",
        '".$arreglo[$i]['Imagen']."',
        '".$arreglo[$i]['Nombre']."', 
        '".$arreglo[$i]['Precio']."',
        '".$arreglo[$i]['Cantidad']."',
        '".($arreglo[$i]['Precio']*$arreglo[$i]['Cantidad'])."'
        )")or die(mysqli_error($con));
    }
    unset($_SESSION['carrito']);
    header("Location: pedidook");
?>
    
asked by Gaston Slaiman 11.06.2018 в 04:14
source

1 answer

0

You have an error in your function mysqli_query() , this function receives two values: The connection to the database and the query. You can learn more about this feature here .

In your first function, $re=mysqli_query($con, "SELECT * from compras order by numeroventa DESC limit 1") or die(mysqli_error($con)); , delete or die remaining:

$re=mysqli_query($con, "SELECT * from compras order by numeroventa DESC limit 1");

In your second function you must do the same so that it is without the or die :

  mysqli_query("UPDATE compras SET (numeroventa, imagen,nombre,precio,cantidad,subtotal) values(
    ".$numeroventa.",
    '".$arreglo[$i]['Imagen']."',
    '".$arreglo[$i]['Nombre']."', 
    '".$arreglo[$i]['Precio']."',
    '".$arreglo[$i]['Cantidad']."',
    '".($arreglo[$i]['Precio']*$arreglo[$i]['Cantidad'])."'
    )"); 
    
answered by 11.06.2018 / 09:07
source