请在这里是我的代码
$actor=$_SESSION['ID'];
$code= $_SESSION['order_code'];
$quantity_invoiced= $_POST['invoice'];
$price= $_POST['price'];
$charge= $_POST['tax'];
$total_items= $_POST['count'];
$account= $_POST['account'];
//first step update order table
for($y=0;$y<$total_items;$y++){
echo $price1 = round($price[$y]);
echo $quantity_invoiced1 = $quantity_invoiced[$y];
echo $charge1 = round($charge[$y]);
print_r( $insert_query="update tbl_order SET GENERAL_LEDGER='{$account}',RECEIVED='1',INVOICED_PRICE='{$price1}',QUANTITY_INVOICED='{$quantity_invoiced1}',CHARGES='{$charge1}',TOTAL_COST='{$price1}*{$quantity_invoiced1}' WHERE ORDER_CODE='{$code}' AND ACTOR='{$actor}'");
$stmt = $con->prepare( $insert_query );
$stmt->execute() ;
}
答案 0 :(得分:0)
这不是您准备查询的方式,请调整为:
//params
session_start();
$actor=$_SESSION['ID'];
$code= $_SESSION['order_code'];
$quantity_invoiced= $_POST['invoice'];
$price= $_POST['price'];
$charge= $_POST['tax'];
$total_items= $_POST['count'];
$account= $_POST['account'];
if(!$con){
echo 'conn failed';
die(print_r($con->errorInfo()));
}
$insert_query="
UPDATE tbl_order
SET GENERAL_LEDGER = ?,
RECEIVED='1',
INVOICED_PRICE = ?,
QUANTITY_INVOICED = ?,
CHARGES=?,
TOTAL_COST=?,
WHERE ORDER_CODE=? AND ACTOR= ?");
if($stmt = $con->prepare($insert_query){
for($y=0;$y<$total_items;$y++){
//other params
$price1 = round($price[$y]);
$quantity_invoiced1 = $quantity_invoiced[$y];
$charge1 = round($charge[$y]);
$total_cost = $price1 * $quantity_invoiced1;
$params = array($account,
$price1,
$quantity_invoiced1,
$charge1,
$total_cost,
$code,
$actor)
var_dump($params);//use this to see
if($stmt->execute($params)){
if($stmt->rowCount() > 0){
echo 'update successful';
}else{
echo 'did not affect any rows';
}
}else{
echo 'execute failed';
die(print_r($con->errorInfo()));
}
}
}else{
echo 'prepare failed';
die(print_r($con->errorInfo()));
}