if(isset($_POST["create_invoice"]))
{
$sub_total = 0;
$discount = 0;
$total_after_discount = 0;
$statement = $conn->prepare("
INSERT INTO tbl_medlab
(order_no, order_date, order_receiver_name, order_receiver_address, sub_total, discount, total_after_discount,order_datetime)
VALUES (:order_no, :order_date, :order_receiver_name, :order_receiver_address, :sub_total, :discount, :total_after_discount, :order_datetime)
");
$statement->execute(
array(
':order_no' => trim($_POST["order_no"]),
':order_date' => trim($_POST["order_date"]),
':order_receiver_name' => trim($_POST["order_receiver_name"]),
':order_receiver_address' => trim($_POST["order_receiver_address"]),
':sub_total' => $sub_total,
':discount' => $discount,
':total_after_discount' => $total_after_discount,
':order_datetime' => date("Y-m-d")
)
);
$statement = $conn->query("SELECT LAST_INSERT_ID()");
$order_id = $statement->fetchColumn();
for($count=0; $count<$_POST["total_item"]; $count++)
{
$sub_total = $sub_total + floatval(trim($_POST["order_item_actual_amount"][$count]));
$discount = $discount + floatval(trim($_POST["discount_amount"][$count]));
$total_after_discount = $total_after_discount + floatval(trim($_POST["order_item_final_amount"][$count]));
$statement = $conn->prepare("
INSERT INTO tbl_medlab_item
(order_id,item_type, item_name, order_item_quantity, order_item_price, order_item_actual_amount, discount, discount_amount, order_item_final_amount)
VALUES (:order_id, :item_type, :item_name, :order_item_quantity, :order_item_price, :order_item_actual_amount, :discount, :discount_amount, :order_item_final_amount)
");
$statement->execute(
array(
':order_id' => $order_id,
':item_name' => trim($_POST["item_name"][$count]),
':order_item_quantity' => trim($_POST["order_item_quantity"][$count]),
':order_item_price' => trim($_POST["order_item_price"][$count]),
':order_item_actual_amount' => trim($_POST["order_item_actual_amount"][$count]),
':discount' => trim($_POST["discount"][$count]),
':discount_amount' => trim($_POST["discount_amount"][$count]),
//ERROR PART START HERE
':order_item_final_amount' => trim($_POST["order_item_final_amount"][$count])
//ERROR PART END'S HERE
)
);
}
$total_after_discount = $sub_total - $discount ;
$statement = $conn->prepare("
UPDATE tbl_medlab
SET sub_total = :sub_total,
discount = :discount,
total_after_discount = :total_after_discount
WHERE order_id = :order_id
");
$statement->execute(
array(
':sub_total' => $sub_total,
':discount' => $discount,
':total_after_discount' => $total_after_discount,
':order_id' => $order_id
)
);
header("location:md_sale.php");
}
I am getting an error part on line 74:
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:xampphtdocsSanRem MD LABmd_sale.php:74 Stack trace: #0 C:xampphtdocsSanRem MD LABmd_sale.php(74): PDOStatement->execute(Array) #1 {main} thrown in C:xampphtdocsSanRem MD LABmd_sale.php on line 74
I already exhausted all the possible fixes but it is always showing that error.
I was expecting for it to save the data to the database after I click on Create Invoice but then this error show up.