2. 顯示使用者送出的資訊 並且如果有欄位為空則轉頁到 PHA01-3.php
程式碼說明開始-------------------------------------------------------------------
<?
$t1=$_POST["T1"]; //接收 PHA01-1.php 使用者所傳入的值
$t2=$_POST["T2"];
$d1=$_POST["D1"];
$r1=$_POST["R1"];
$c1=$_POST["C1"];
$c2=$_POST["C2"];
$c3=$_POST["C3"];
$c4=$_POST["C4"];
$c5=$_POST["C5"];
$c6=$_POST["C6"];
$c7=$_POST["C7"];
$c="abc";
if (($c1 != "ON") && ($c2 != "ON") && ($c3 != "ON") && ($c4 != "ON") && ($c5 != "ON") && ($c6 != "ON") && ($c7 != "ON") ) {
$c=""; //如果使用者都沒有選擇任何一天 則讓 $c 為空字串
}
if ( ($t1 == null) || ($t2 == null) || ($c == null) ) { //如果使用者有 姓名 電子郵件 天數 任一個未選擇 就轉頁面到 PHA01-3.php
header("locationHA01-3.php?t1=".$t1."&t2=".$t2."&c=".$c);
}
else { //顯示使用者填入的資訊
$p = "<h2>".$t1."先生/小姐您好:</h2><br>";
$p = $p."您選擇了:<b>".$d1."</b><br>";
$p = $p."房型為:<b>".$r1."</b><br>";
function get_price($a,$b,$z) { //價格函數
switch ($a) {
case "國賓大飯店":
if ( $b == "單人房" ) {
$pp = 2580;
}
else {
$pp = 3150;
}
if ( $z == "u" ) {
$pp = $pp * 1.1;
}
break;
case "中信大飯店":
if ( $b == "單人房" ) {
$pp = 2450;
}
else {
$pp = 2650;
}
if ( $z == "u" ) {
$pp = $pp * 1.09;
}
break;
default:
if ( $b == "單人房" ) {
$pp = 3950;
}
else {
$pp = 4250;
}
if ( $z == "u" ) {
$pp = $pp * 1.12;
}
}
return $pp;
}
//依照資訊來計算房價
$q = "";
$y = "a";
if ( $c1 == "ON" ) {
$q = $q." 星期日 ";
$pp = $pp + get_price($d1,$r1,$y);
}
if ( $c2 == "ON" ) {
$q = $q." 星期一 ";
$pp = $pp + get_price($d1,$r1,$y);
}
if ( $c3 == "ON" ) {
$q = $q." 星期二 ";
$pp = $pp + get_price($d1,$r1,$y);
}
if ( $c4 == "ON" ) {
$q = $q." 星期三 ";
$pp = $pp + get_price($d1,$r1,$y);
}
if ( $c5 == "ON" ) {
$q = $q." 星期四 ";
$pp = $pp + get_price($d1,$r1,$y);
}
if ( $c6 == "ON" ) {
$q = $q." 星期五 ";
$y="u";
$pp = $pp + get_price($d1,$r1,$y);
}
if ( $c7 == "ON" ) {
$q = $q." 星期六 ";
$y="u";
$pp = $pp + get_price($d1,$r1,$y);
}
$q = "您預訂入住天數為:<b>".$q."</b><br><br>";
echo $p.$q;
echo "您總共需要花費:".round($pp)."元新台幣.";
}
?>
<body>
<form action="HA01-1.php" method="post">
<input type="submit" value="回主畫面">
</form>
</body>
程式碼說明結束-------------------------------------------------------------------- <?
- $t1=$_POST["T1"];
- $t2=$_POST["T2"];
- $d1=$_POST["D1"];
- $r1=$_POST["R1"];
- $c1=$_POST["C1"];
- $c2=$_POST["C2"];
- $c3=$_POST["C3"];
- $c4=$_POST["C4"];
- $c5=$_POST["C5"];
- $c6=$_POST["C6"];
- $c7=$_POST["C7"];
- $c="abc";
- if (($c1 != "ON") && ($c2 != "ON") && ($c3 != "ON") && ($c4 != "ON") && ($c5 != "ON") && ($c6 != "ON") && ($c7 != "ON") ) {
- $c="";
- }
-
- if ( ($t1 == null) || ($t2 == null) || ($c == null) ) {
- header("location:PHA01-3.php?t1=".$t1."&t2=".$t2."&c=".$c);
- }
- else {
- $p = "<h2>".$t1."先生/小姐您好:</h2><br>";
- $p = $p."您選擇了:<b>".$d1."</b><br>";
- $p = $p."房型為:<b>".$r1."</b><br>";
-
- function get_price($a,$b,$z) {
- switch ($a) {
- case "國賓大飯店":
- if ( $b == "單人房" ) {
- $pp = 2580;
- }
- else {
- $pp = 3150;
- }
- if ( $z == "u" ) {
- $pp = $pp * 1.1;
- }
- break;
- case "中信大飯店":
- if ( $b == "單人房" ) {
- $pp = 2450;
- }
- else {
- $pp = 2650;
- }
- if ( $z == "u" ) {
- $pp = $pp * 1.09;
- }
- break;
- default:
- if ( $b == "單人房" ) {
- $pp = 3950;
- }
- else {
- $pp = 4250;
- }
- if ( $z == "u" ) {
- $pp = $pp * 1.12;
- }
- }
- return $pp;
- }
-
-
-
- $q = "";
- $y = "a";
- if ( $c1 == "ON" ) {
- $q = $q." 星期日 ";
- $pp = $pp + get_price($d1,$r1,$y);
- }
- if ( $c2 == "ON" ) {
- $q = $q." 星期一 ";
- $pp = $pp + get_price($d1,$r1,$y);
- }
- if ( $c3 == "ON" ) {
- $q = $q." 星期二 ";
- $pp = $pp + get_price($d1,$r1,$y);
- }
- if ( $c4 == "ON" ) {
- $q = $q." 星期三 ";
- $pp = $pp + get_price($d1,$r1,$y);
- }
- if ( $c5 == "ON" ) {
- $q = $q." 星期四 ";
- $pp = $pp + get_price($d1,$r1,$y);
- }
- if ( $c6 == "ON" ) {
- $q = $q." 星期五 ";
- $y="u";
- $pp = $pp + get_price($d1,$r1,$y);
- }
- if ( $c7 == "ON" ) {
- $q = $q." 星期六 ";
- $y="u";
- $pp = $pp + get_price($d1,$r1,$y);
- }
-
- $q = "您預訂入住天數為:<b>".$q."</b><br><br>";
- echo $p.$q;
- echo "您總共需要花費:".round($pp)."元新台幣.";
- }
- ?>
- <body>
- <form action="PHA01-1.php" method="post">
- <input type="submit" value="回主畫面">
- </form>
- </body>
複製代碼 |