错误: SQLSTATE[HY093]: 参数编号无效: 参数未定义 PDO



我是PHP新手,我正在使用SlimFramework 3开发API

我有这个开机自检方法

$app->post('/factura', function(Request $request, Response $response){
$conn = PDOConnection::getConnection()
try{
$sql = "INSERT INTO bd_zapateria.factura
(
idCliente,
idEmpleado,
fechaFactura,
subTotal,
descuento,
Impuesto,
totalFactura)
VALUES
(:idCliente,
:idEmpleado,
:fechaFactura,
:subtotal,
:descuento,
:Impuesto,
:totalFactura)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':idCliente', $idCliente);
$stmt->bindParam(':idEmpleado', $idEmpleado);
$stmt->bindParam(':fechaFactura', $fechaFactura);
$stmt->bindParam(':subTotal', $subTotal);
$stmt->bindParam(':descuento', $descuento);
$stmt->bindParam(':Impuesto', $Impuesto);
$stmt->bindParam(':totalFactura', $totalFactura);
$idCliente = (int) $request->getParam("idCliente");
$idEmpleado = (int) $request->getParam("idEmpleado");
$fechaFactura = $request->getParam("fechaFactura");
$subTotal = (int) $request->getParam("subTotal");
$descuento = (int) $request->getParam("descuento");
$Impuesto = (int) $request->getParam("Impuesto");
$totalFactura = (int) $request->getParam("totalFactura");

$result = $stmt->execute();
echo "New records created successfully";
echo($result);
$data['Factura'] = $result;
$response = $response->withHeader('Content-Type','application/json');
$response = $response->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization');
$response = $response->withHeader('Access-Control-Allow-Origin', '*');
$response = $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
$response = $response->withStatus(200);
$response = $response->withJson($data);
return $response;
}catch (PDOException $e) {
$this['logger']->error("DataBase Error.<br/>" . $e->getMessage());
echo "Error: " . $e->getMessage();
} catch (Exception $e) {
$this['logger']->error("General Error.<br/>" . $e->getMessage());
echo "Error: " . $e->getMessage();
} finally {
// Destroy the database connection
$conn = null;
}
}); 

当我尝试使用 Postman 发送值时,它会返回此错误:

错误: SQLSTATE[HY093]: 无效的参数编号: 参数不是 定义

我在邮递员中有正确的标题

占位符:subtotal在绑定中不存在。绑定名称为:subTotal。更正查询或绑定中的大小写,它应该可以工作。

$stmt->bindParam(':subtotal', $subTotal);

最新更新