首页 > 解决方案 > 单击 DIV 时需要帮助尝试进行会话(PHP MYSQL)

问题描述

我正在尝试在单击 div 时进行会话,但我似乎无法让它工作,我正在尝试制作预订表格,然后制作贝宝,因为它的付款一直在尝试其他方法来使用其他贝宝付款但这是唯一一个似乎有效但它只会从贝宝用户信息中保存其数据

这是我的 PHP 文件

<?php
// Redirect to the home page if id parameter not found in URL
if(empty($_GET['id'])){
    header("Location: index.php");
}

// Include and initialize database class
include 'DB.class.php';
$db = new DB;

// Include and initialize paypal class
include 'PaypalExpress.class.php';
$paypal = new PaypalExpress;

// Get product ID from URL
$productID = $_GET['id'];

// Get product details
$conditions = array(
    'where' => array('id' => $productID),
    'return_type' => 'single'
);
$productData = $db->getRows('products', $conditions);

// Redirect to the home page if product not found
if(empty($productData)){
    header("Location: index.php");
}
?>
<form method="post">
    <label>Full Name</label><br>
    <input type="text" name="fullname"><br>
    <label>Contact Number</label><br>
    <input type="number" name="contactno"><br>
    <label>Email</label><br>
    <input type="email" name="email"><br>
    <label>Address</label><br>
    <input type="text" name="address"><br>
    <label>Check In</label><br>
    <input type="date" name="datein"><br>
    <label>Check Out</label><br>
    <input type="date" name="dateout"><br>
    <label>Room Type</label><br>
    <select name="roomtype">
        <option value="Standard">Standard</option>
        <option value="Deluxe">Deluxe</option>
    </select><br>
    <!-- Product details -->
    <p>Name: <?php echo $productData['name']; ?></p>
    <p>Price: <?php echo $productData['price']; ?></p>

    <!-- Checkout button -->
    <div id="paypal-button"></div>
</form>

<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

<!--
JavaScript code to render PayPal checkout button
and execute payment
-->
<script>
paypal.Button.render({
    // Configure environment
    env: '<?php echo $paypal->paypalEnv; ?>',
    client: {
        sandbox: '<?php echo $paypal->paypalClientID; ?>',
        production: '<?php echo $paypal->paypalClientID; ?>'
    },
    // Customize button (optional)
    locale: 'en_US',
    style: {
        size: 'small',
        color: 'gold',
        shape: 'pill',
    },
    // Set up a payment
    payment: function (data, actions) {
        return actions.payment.create({
            transactions: [{
                amount: {
                    total: '<?php echo $productData['price']; ?>',
                    currency: 'PHP'
                }
            }]
      });
    },
    // Execute the payment
    onAuthorize: function (data, actions) {
        return actions.payment.execute()
        .then(function () {
            // Show a confirmation message to the buyer
            //window.alert('Thank you for your purchase!');

            // Redirect to the payment process page
            window.location = "process.php?paymentID="+data.paymentID+"&token="+data.paymentToken+"&payerID="+data.payerID+"&pid=<?php echo $productData['id']; ?>";
        });
    }
}, '#paypal-button');
</script>

标签: javascriptphpmysqlajaxpaypal

解决方案


推荐阅读