$arrParam['total'] = $_SESSION['pay']; } else { $arrParam['total'] = $total_price; } if (isset($_SESSION['coupon'])) { $arrParam['sale'] = $_SESSION['coupon']; } if (isset($_SESSION['code_id'])) { $arrParam['code_id'] = $_SESSION['code_id']; } $arrParam['total_amount'] = $total_amount; $column = $valuee = ""; foreach ($arrParam as $key => $value) { $column .= "{$key}" . ","; $values .= "'" . $value . "'" . ","; } $column = rtrim($column, ","); $values = rtrim($values, ","); $sql = "INSERT INTO orders(" . $column . ") VALUES (" . $values . ")"; mysql_query($sql) or die(mysql_error()); $order_id = mysql_insert_id(); foreach ($_SESSION['cart'] as $key => $value) { $product_id = $value['id']; $product_name = $value['product_name']; $amount = $value['soluong']; $price = $value['giatien']; $total = $value['tientheosp']; $product_id = $value['id']; $model->insertOrderDetail($order_id, $product_id, $product_name, $amount, $price, $total); } unset($_SESSION['cart']);