【发布时间】:2022-11-26 12:23:46
【问题描述】:
我正在尝试加载销售、打折库存,但出现此错误
警告:尝试在第 28 行的 C:\xampp\htdocs\veterinaria\terminarVenta.php 中的数组中读取属性“total”
警告:尝试在第 29 行的 C:\xampp\htdocs\veterinaria\terminarVenta.php 中的数组中读取属性“id”
警告:尝试在第 29 行的 C:\xampp\htdocs\veterinaria\terminarVenta.php 中的数组中读取属性“cantidad”
`
<?php if(!isset($_POST["total"])) exit; session_start(); $total = $_POST["total"]; include_once "conexion.php"; $ahora = date("Y-m-d H:i:s"); $sentencia = $base_de_datos->prepare("INSERT INTO ventas(fecha, total) VALUES (?, ?);"); $sentencia->execute([$ahora, $total]); $sentencia = $base_de_datos->prepare("SELECT id FROM ventas ORDER BY id DESC LIMIT 1;"); $sentencia->execute(); $resultado = $sentencia->fetch(PDO::FETCH_OBJ); $idVenta = $resultado === false ? 1 : $resultado->id; var_dump($_SESSION["carrito"]); $base_de_datos->beginTransaction(); $sentencia = $base_de_datos->prepare("INSERT INTO productos_vendidos(id_producto, id_venta, cantidad) VALUES (?, ?, ?);"); $sentenciaExistencia = $base_de_datos->prepare("UPDATE productos SET existencia = existencia - ? WHERE id = ?;"); foreach ($_SESSION["carrito"] as $producto) { $total += $producto->total; $sentencia->execute([$producto->id, $idVenta, $producto->cantidad]); $sentenciaExistencia->execute([$producto->cantidad, $producto->id]); } $base_de_datos->commit(); unset($_SESSION["carrito"]); $_SESSION["carrito"] = []; header("Location: ./vender.php?status=1"); ?>`
我不知道这个错误试图告诉我什么,因为这是我第一次发生这个错误 var_dump($_SESSION["carrito"]) 是 array(1) { [0]=> array(7) { ["id"]=> string(1) "1" ["codigo"]=> string(1) "1" ["descripcion"]=> string(7) “bozales” [“precioVenta”]=> string(6) “150.00” [“existencia”]=> string(6) “200.00” [“cantidad”]=> int(1) [“total” ]=> 字符串(6) "150.00" } }
【问题讨论】: