PHP&使用PayPal集成代码的HTML将无法使用

时间:2015-08-29 07:48:18

标签: php html paypal

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

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

最后我需要一个网页,根据用户选择的产品选项(8gb ram而不是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>

感谢任何帮助,我们非常感激。

1 个答案:

答案 0 :(得分:0)

onclick =“”这不起作用,onclick只能执行javascript。我认为不需要在这里使用PHP,javascript可以完成你期望的功能。