Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我的提交按钮没有重定向_Php - Fatal编程技术网

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

Php 为什么我的提交按钮没有重定向,php,Php,我有一个带有提交按钮的表单 <input type="submit" name="submitOrder" id="submitOrder" value="Purchase" class="btn btn-warning"> 下面是几行代码: <?php if (isset($_POST['submitOrder'])) { header ("location:payment.php?discount=". $discountCode ."");

我有一个带有提交按钮的表单

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

下面是几行代码:

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

为什么单击该按钮时,除了重新加载页面外,什么也不做?我想让它将用户重定向到payment.php

带提交按钮的整个表单

<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>

数量
名称
价格
总计
删除

确保返回的第一个项目是标题,前面没有空格或任何内容,即回音或文本

检查日志文件中是否存在已发送的标题错误


确保按钮位于表单内部

问题是,在发送重定向标题之前,有输出,因为您的条件在html部分

在将任何输出发送到客户端之前,应该将代码与重定向一起放置。
另一个选项是打开输出缓冲,但这也必须在向客户端发送内容之前完成。

从中发布代码您可以发布完整的代码吗?您确定在
header()之前没有任何输出吗?可能您对表单使用get请求?整个表单很长,但我已将其添加到上述问题中。