odate; $customer = $data->customer; $menus = $data->menus; $bko = $data->bkid; //$qty = $data->qty; //$ucost = $data->ucost; $orderno = $data->orderno; //check if the order has been placed before $chk = $DBcon->prepare("select * from order_main where (customer_details = '$customer' and menus = '$menus') and (trans_date = '$odate')") ; $chk->execute() ; if($chk->rowcount() > 0) { $del = $DBcon->prepare("delete from ordertemp") ; if($del->execute()) echo "Limit Violated" ; } else { $gtcost = $DBcon->prepare("select sum(totalcost) as tcost from ordertemp where order_id = '$orderno'") ; $gtcost->execute() ; $gtrow = $gtcost->fetch(pdo::FETCH_ASSOC) ; $tc = $gtrow['tcost'] ; $insertmain = $DBcon->prepare("insert into order_main(trans_id,booking_id,customer_details,menus,amount,trans_date,staff) values('$orderno','$bko','$customer','$menus','$tc',NOW(),'$adm')") ; if($insertmain->execute()) { $sel = $DBcon->prepare("select * from ordertemp where order_id = '$orderno'") ; $sel->execute() ; while($row = $sel->fetch(pdo::FETCH_ASSOC) ) { $items = $row['item'] ; $quantity = $row['quantity'] ; $unitc = $row['unitcost'] ; $tcost = $quantity * $unitc ; $insertd = $DBcon->prepare("insert into order_details(trans_id,items,quantity,unitc,total_cost) values('$orderno','$items','$quantity','$unitc','$tcost')") ; $insertd->execute() ; } $del = $DBcon->prepare("delete from ordertemp") ; if($del->execute()) echo "Order Placed Successfully" ; } } ?>