使用标题重定向到其他页面

时间:2013-12-24 09:26:20

标签: php

这是我的情况:

只是一个正常形式:

<form action="#" method="post" name="frm">

<input type="radio" name="building" value="studio" id="studio" checked/><label for="studio">Studio</label>
<input type="radio" name="building" value="rijwoning" id="rijwoning"/><label for="rijwoning">Maison</label>

<input type="checkbox" name="ek" value="1" id="ek"/><label for="ek">ek</label>
<input type="checkbox" name="epc" value="1" id="epc"/><label for="epc">epc</label>
<input type="checkbox" name="gk" value="1" id="gk"/><label for="gk">gk</label>



<label for="firstname" class="labelcontact">First Name</label><input type="text" name="firstname" id="firstname" class="contactinput"/>
<label for="name" class="labelcontact">Name</label><input type="text" name="name" id="name" class="contactinput"/>

<input class="submitbutton" type="submit" value="Send" alt=""Send/>
    </form>

这是我的PHP代码:

<?php 
session_start();

$building = $_POST['building'];
$firstname = $_POST['firstname'];
$name = $_POST['name'];

$escapefirstname = mysqli_real_escape_string($firstname);
$escapename = mysqli_real_escape_string($name);

$value = 0;
$discount = 0;

if (!empty($_REQUEST['ek'])){
    $value = 115;
    $controltype = 'elektrische keuring';
}

if (!empty($_REQUEST['ek']) && !empty($_REQUEST['epc'])){
    $value = 125;
    $controltype = 'elektriciteit, energiecertificaat';
    //$ek_chk = true;
    }


    if (!empty($_REQUEST['epc']) && ($building === 'studio')){  
            $value += 115; 
        }
    elseif (!empty($_REQUEST['epc']) && ($building === 'rijwoning')){ 
            $value += 165;
            $discount = 10;
        }


    if (!empty($_REQUEST['gk'])){
        $value += 130;
    } 

    if (!empty($_REQUEST['ek']) && !empty($_REQUEST['epc']) && !empty($_REQUEST['gk'])){
        $controltype = 'elektriciteit, energiecertificaat, gaskeuring';
    }


    $total = $value - $discount;

$con= mysqli_connect("********","********","***********","***********");

    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    }

$queryorder = 'INSERT INTO `cd_order`
    (`order_building`, `order_firstname`, `order_name`, `order_total`)
VALUES 
("'.$building.'","'.$firstname.'","'.$name.'","'.$total.'")' ;

$result = mysqli_query($con, $queryorder);
        if (!$result) {
        printf("error: %s\n", mysqli_error($con));
        }  

$orderid = $con->insert_id;



mysqli_close($con);

    if (!empty($total) && !empty($orderid)){
    $_SESSION['orderid'] = $orderid;
    $_SESSION['total'] = $total;
        header('location: finish.php') ;
    }
    else {
        echo 'error! please try again later!';
    }
?>

我的完成页面是来自支付公司人员的预制安全页面,我只需要添加动态价格和唯一ID(来自上一页)。这就是我使用$ _SESSION的原因。

<?php

    session_start();

    $end_total = $_SESSION['total'] * 100;
    $num_commande = $_SESSION['orderid'];

?>

一切正常,除了我的“标题”它停留在表单页面上...我希望能够在表单写完后将表单页面中的变量($ total&amp; $ orderid)发送到完成页面进入我的数据库&amp;我的总数已计算出来(见代码)。

我的弃儿在哪里(请记住我正处于PHP的学习阶段)

谢谢!

2 个答案:

答案 0 :(得分:0)

你写了错误的语法'location'的header.use这段代码

header('Location: finish.php') ;

答案 1 :(得分:0)

您是说要将页面从表单页面重定向到完成页面发送$ total和$ orderid的值?如果是这样,您可以像这样使用标题函数:

header('Location: finish.php?total=' . $total . '&orderid=' . $orderid. ');
exit();

在此之后,您可以在finish.php

中检索$ total和$ orderid变量值