duanqin9631 2015-10-19 09:58
浏览 20

为什么我的提交按钮没有重定向

I have a form with a submit button.

<input type="submit" name="submitOrder" id="submitOrder" value="Purchase" class="btn btn-warning">

Below this I have a couple lines of code:

<?php
    if (isset($_POST['submitOrder'])) {
        header ("location:payment.php?discount=". $discountCode ."");
    }
?>

Why does that button when clicked, do nothing but reload the page? I want it to redirect the user to payment.php?

Entire form with the submit button...

<form method="post" action="cart_update.php">
    <div class="row" style="padding-bottom: 10px;">
        <div class="col-md-2">
            <strong>Quantity</strong>
        </div>
        <div class="col-md-3">
            <strong>Name</strong>
        </div>
        <div class="col-md-2">
            <strong>Price</strong>
        </div>
        <div class="col-md-2">
            <strong>Total</strong>
        </div>
        <div class="col-md-3">
            <strong>Remove</strong>
        </div>
    </div>

    <?php
        if(isset($_SESSION["cart_products"])) { // Check session var
            $total = 0; // Set initial total value

            foreach ($_SESSION["cart_products"] as $cart_itm) {
                // Set variables to use in content below
                $ProductName = $cart_itm["ProductName"];
                $product_qty = $cart_itm["product_qty"];
                $Price = $cart_itm["Price"];
                $ProductCode = $cart_itm["ProductCode"];
                $subtotal = ($Price * $product_qty); // Calculate Price x Qty
                echo '<div class="row" style="padding: 10px 0;">';
                echo '<div class="col-md-2">Qty: <input type="text" size="2" maxlength="4" name="product_qty['. $ProductCode .']" value="'. $product_qty .'" /></div>';
                echo '<div class="col-md-3">Product Name: '. $ProductName .'</div>';
                echo '<div class="col-md-2">Price: '. $currency . $Price .'</div>';
                echo '<div class="col-md-2">Total: £';
                echo money_format('%i', $subtotal);             
                echo '</div>';                      
                echo '<div class="col-md-3"><input type="checkbox" name="remove_code[]" value="'. $ProductCode .'" /></div>';
                echo '</div>';
                echo '<hr>';
                $total = ($total + $subtotal); // Add subtotal to total var
                $grand_total = $Price * $product_qty;
            }

            $grand_total = $total + $shipping_cost; // Grand total including shipping cost
            foreach($taxes as $key => $value) { // List and calculate all taxes in array
                $tax_amount = round($total * ($value / 100));
                $tax_item[$key] = $tax_amount;
                $grand_total = $grand_total + $tax_amount;  // Add tax val to grand total
            }

            $list_tax = '';

            foreach($tax_item as $key => $value) { // List all taxes
                $list_tax .= $key. ' : '. $currency . sprintf("%01.2f", $value).'<br />';
            }

            $shipping_cost = ($shipping_cost) ? 'Shipping Cost: ' . $currency . sprintf("%01.2f", $shipping_cost).'<br />':'';
        }
    ?>

    <br />

    <div class="row">
        <span style="float: right; text-align: right; width: 100%;">Amount Payable: <strong>£<?php echo sprintf("%01.2f", $_SESSION['grand_total'] = $grand_total); ?><br />Price inc. VAT and Postage + Packaging</strong><br />Discount Code: <input type="text" name="discountCode" id="discountCode" value="TEST" /></span>

        <br />
        <br />

        <a href="index.php" class="btn btn-warning">Continue Shopping</a>
        <button type="submit" class="btn btn-warning">Update</button>
        <!-- <a href="payment.php" class="btn btn-warning">Purchase</a> -->
        <input type="submit" name="submitOrder" id="submitOrder" value="Purchase" class="btn btn-warning">

        <?php
            if (isset($_POST['submitOrder'])) {
                header ("location:payment.php?discount=". $discountCode ."");
            }
            $_SESSION['ProductName'] = $ProductName;
            $_SESSION['product_qty'] = $product_qty;
            $_SESSION['grand_total'] = $grand_total;
        ?>
    </div>

    <input type="hidden" name="return_url" value="<?php $current_url = urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); echo $current_url; ?>" />
</form>
  • 写回答

2条回答 默认 最新

  • duangou1953 2015-10-19 10:02
    关注

    ensure the very first item returned is the header with no whitespace or anything before it ie echos or text,

    check the log files for headers already sent errors

    make sure the button is inside the form

    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。