function total_price($cart)
{
    $price = 0.0;
    if (is_array($cart)) {
        foreach ($cart as $isbn => $qty) {
            $bookprice = getbookprice($isbn);
            if ($bookprice) {
                $price += $bookprice * $qty;
            }
        }
    }
    return $price;
}
$card_number = $_POST['card_number'];
$card_PID = $_POST['card_PID'];
$card_expire = strtotime($_POST['card_expire']);
$card_owner = $_POST['card_owner'];
// find customer
$customerid = getCustomerId($name, $address, $city, $zip_code, $country);
if ($customerid == null) {
    // insert customer into database and return customerid
    $customerid = setCustomerId($name, $address, $city, $zip_code, $country);
}
$date = date("Y-m-d H:i:s");
insertIntoOrder($conn, $customerid, $_SESSION['total_price'], $date, $name, $address, $city, $zip_code, $country);
// take orderid from order to insert order items
$orderid = getOrderId($conn, $customerid);
foreach ($_SESSION['cart'] as $isbn => $qty) {
    $bookprice = getbookprice($isbn);
    $query = "INSERT INTO order_items VALUES \n\t\t('{$orderid}', '{$isbn}', '{$bookprice}', '{$qty}')";
    $result = mysqli_query($conn, $query);
    if (!$result) {
        echo "Insert value false!" . mysqli_error($conn2);
        exit;
    }
}
session_unset();
?>
	<p class="lead text-success">Your order has been processed sucessfully. Please check your email to get your order confirmation and shipping detail!. 
	Your cart has been empty.</p>

<?php 
if (isset($conn)) {
    mysqli_close($conn);