error con insert un array a una tabla phpmyadmin
Publicado por Julio Ceballos (3 intervenciones) el 28/07/2020 23:33:06
el siguiente codigo trae los datos de una tabla y lo decodifica y cuando le doy a gravar grava solo el ultimo registro...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
static public function mdleditardetarllevta($tabla, $datos, $datos1, $datos3){
$listaProductosvtaedit = json_decode($datos3, true);
var_dump("$listaProductosvtaedit",$listaProductosvtaedit);
$totalitemvtaedit = sizeof($listaProductosvtaedit);
for ($i = 0; $i <= $totalitemvtaedit; $i++) {
$stmt = Conexion::conectar()->prepare("INSERT INTO $tabla (codigovta, codigoprod, cantidadvta, valor, total, porcimpuesto) VALUES (:codigovta, :codigoprodvta, :cantidadvta, :valorvta, :totalvta, :porcimpuesto)");
$stmt->bindParam(":codigovta", $datos, PDO::PARAM_INT);
$stmt->bindParam(":porcimpuesto", $datos1, PDO::PARAM_INT);
$stmt->bindParam(":codigoprodvta", $listaProductosvtaedit[$i]["id"], PDO::PARAM_INT);
$stmt->bindParam(":cantidadvta", $listaProductosvtaedit[$i]["cantidad"], PDO::PARAM_INT);
$stmt->bindParam(":valorvta", $listaProductosvtaedit[$i]["precio"], PDO::PARAM_INT);
$stmt->bindParam(":totalvta", $listaProductosvtaedit[$i]["total"], PDO::PARAM_INT);
$stmt->execute();
}
if($stmt->execute()){
return "ok";
}else{
return "error";
}
$stmt->close();
$stmt = null;
}
Valora esta pregunta


0