【问题标题】:PHP & HTML with PayPal integration code won't work带有 PayPal 集成代码的 PHP 和 HTML 不起作用
【发布时间】:2015-11-23 20:54:03
【问题描述】:

我现在正在尝试使用 PHP 创建一个系统,该系统将计算出用户购买的产品的成本。基本上我不想有很多单选按钮,这取决于用户选择的价格变化。

在下面的代码中,您将能够看到我的 PHP。显然,我的 HTML 这可能会让我更好地了解我想要实现的目标。这是我第一次用 PHP 编码,我通常使用 JavaScript,所以我预计可能会有一些错误,请帮助我!

最后,基本上我需要一个网页,根据用户选择的产品选项(8gb 内存而不是 4gb 和 500gb 驱动器而不是 1tb 等)向 PayPal 按钮提交自定义金额。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Silicon Build</title>
        <link rel="stylesheet" href="stylesheets/app.css">
        <script src="bower_components/modernizr/modernizr.js"></script>
        <!-- Custom CSS Stylesheet -->
        <link rel="stylesheet" href="scss/app.css">
        <!-- Custom Fonts -->
        <link href='http://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'>
        <?php
            function updateTotal($type, $price) {
                $cpu = 50;
                $ram = 100;
                $mobo = 150;
                $components = $cpu + $ram + $mobo;
                $shippingMe = 6.90;
                $profit = 35;
                $shipping = 15;
                $original = (300 + $shippingMe + $shipping + $profit + 0.2) /0.966;
                $basePrice = ($components + $shippingMe + $shipping + $profit + 0.2) /0.966;
                $options = $basePrice - $original;
                if ($type == 'cpu') {
                    $cpu = $price;
                } else if ($type == 'ram') {
                    $ram = $price;
                } else if ($type == 'mobo') {
                    $mobo = $price;}
            }
        ?>
    </head>
    <body>
        <!-- Navigational Menu -->
        <?php include_once("header.html"); ?>
        <!-- Main Content -->
        <input type="radio" name="cpu" value="Intel-i5" oncheck="<?php updateTotal('cpu',50); ?>" checked>Intel Core i5 (+£0.00)<br>
        <input type="radio" name="cpu" value="Intel-i7" onclick="<?php updateTotal('cpu',70); ?>">Intel Core i7 (+£20.00)<br>
        <hr>
        <input type="radio" name="ram" value="4gb" onclick="<?php updateTotal('ram',100); ?>" checked>4GB RAM (+£0.00)<br>
        <input type="radio" name="ram" value="8gb" onclick="<?php updateTotal('ram',150); ?>">8GB RAM (+£50.00)<br>
        <hr>
        <input type="radio" name="mobo" value="mobo1" onclick="<?php updateTotal('mobo',150); ?>" checked>Motherboard 1 (+£0.00)<br>
        <input type="radio" name="mobo" value="mobo2" onclick="<?php updateTotal('mobo',175); ?>">Motherboard 2 (+£25.00)<br>
        
        <p id="price"></p>
        <p id="options"></p>
        
        <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
            <input type="hidden" name="cmd" value="_cart">
            <input type="hidden" name="business" value="nick@bayworth.com">
            <input type="hidden" name="lc" value="BM">
            <input type="hidden" name="item_name" value="COMPUTER_NAME">
            <input type="hidden" name="amount" value="<?php echo $basePrice; ?>">
            <input type="hidden" name="currency_code" value="GBP">
            <input type="hidden" name="button_subtype" value="products">
            <input type="hidden" name="no_note" value="0">
            <input type="hidden" name="shipping" value="0.00">
            <input type="hidden" name="add" value="1">
            <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
            <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
            <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
        </form>

        
        <!-- Footer -->
        <?php include_once("footer.html"); ?>
        <!-- Scripts -->
        <script src="bower_components/jquery/dist/jquery.min.js"></script>
        <script src="bower_components/foundation/js/foundation.min.js"></script>
        <script src="js/app.js"></script>
    </body>
</html>

感谢您的任何帮助,非常感谢。

【问题讨论】:

    标签: php html paypal


    【解决方案1】:

    onclick="" 这个不行,onclick 只能执行javascript。我认为这里不需要使用PHP,javascript可以完成您期望的功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      • 2019-09-18
      • 2021-12-28
      相关资源
      最近更新 更多