I have a problem trying to insert an array
This is the insert code
public $campos=array("id_transaccion","id_producto","id_empleado","cantidad","id_cliente","fecha");
public $tabla="ventas";
public $tablaWeb="transacciones";
public function CompraWeb($datos=array(),$cuenta,$id)
{
$arreglo=array();
foreach ($datos as $key=>$value)
{
if(in_array($key,$this->campos))
{
//líena que muestra el arreglo
$arreglo[$key]=$value;
}
}
for ($i=0; $i <count($arreglo) ; $i++) {
print_r($arreglo);
$keys=implode(",",array_keys($arreglo));
$values=implode("','",array_values($arreglo));
$sql=sprintf("insert into %s (%s) values('%s')",$this->tablaWeb,$keys,$values);
if ($this->ValidarCuenta($cuenta,$id) == true)
{
$this->conexion->exec($sql);
echo '<script language="javascript">alert("Compra Exitosa");</script>';
header("Refresh:0; url=../views/ProductosCliente.php");
}
else
{
echo '<script language="javascript">alert("Pongase en contacto con el Administrador para que reciba una cuenta");</script>';
header("Refresh:0; url=../views/ProductosCliente.php");
}
}
}
This is what I get from the controller
<?php
session_start();
include_once ("../model/Ventas.php");
$cuenta=$_POST['cuenta'];
$id=$_POST['id_cliente'];
var_dump($_POST);
var_dump($_SESSION['carrito']);
$conexion=new Ventas();
$conexion->CompraWeb($_SESSION['carrito'],$cuenta,$id);
Show me an arrangement this way ...
array (6) {["product_name"] = > string (8) "Food" ["customer_id"] = > string (1) "1" ["product_id"] = > string (10) "2017-08-08" ["quantity"] = > string (1) "3" ["image_product"] = > string (33) "../images/alimento_para_perro.jpg" ["product_price"] = > string (2) "15"}
It does not throw me any error, it just gets stuck on the page in the controller and does not do anything