我有以下表格,允许用户选择酒店预订的日期/房间。
<form action="booking-form.php" method="post">
<fieldset>
<div class="select-date">
<label>Arrival Date</label>
<select name="arrd" class="day">
<option value="1" >1</option>
... snip ...
<option value="24" selected="selected">24</option>
</select>
<select name="arrm" class="month">
<option value="01" >January</option>
... snip ...
<option value="11" selected="selected">November</option>
</select>
<select name="arry" class="year">
<option value="2009" selected="selected">2009</option>
... snip ...
</select>
</div>
<div class="more">
<div class="info">
<label>Days</label>
<select name="days">
<option value="1">01</option>
... snip ...
<option value="7" selected="selected">07</option>
</select>
</div>
<div class="info">
<label>Rooms</label>
<select name="rooms">
<option value="1">01</option>
... snip ...
</select>
</div>
</div>
<input type="submit" value="Check availabilty"/>
<input type="hidden" name="submitted" value="TRUE"/>
</fieldset>
</form>
这是应该处理从表单传递的变量并通过url传递给预订提供者的php。 当表单只提交一个没有错误的白色屏幕时,没有任何反应。
<?php
ini_set ('display_errors',1);
error_reporting (E_ALL & ~ E_NOTICE);
if (isset($_POST['submitted'])){
$errors = array();
// A bunch of if's for all the fields and the error messages.
if (empty($_POST['arrd'])) {
$errors[] = 'Please select a day';
} else{
$arrd = ($_POST['arrd']);
}
if (empty($_POST['arrm'])) {
$errors[] = 'Please select a month';
} else{
$arrm = ($_POST['arrm']);
}
if (empty($_POST['arry'])) {
$errors[] = 'Please select a year';
} else{
$arry = ($_POST['arry']);
}
if (empty($_POST['non'])) {
$errors[] = 'Please choose a number of nights';
} else{
$non = ($_POST['non']);
}
if (empty($_POST['norooms'])) {
$errors[] = 'Please choose a number of rooms';
} else{
$norooms = ($_POST['norooms']);
}
if (empty($errors)){
$arrdate = $arrd . " " . $arrm ."" . $arry;
$url ="https://portals.uk.rezlynx.net/DHPPORTAL/wfrmpakquery.aspx?SiteID=DHOLDHALL&arrdate=$arrdate&non=$non&norooms=$norooms";
header('Location: $url');
exit();
}
else{
foreach($errors as $msg){
echo"-msg<br/>\n";
}
}
?>
有人能看到我错过的东西吗?
提前致谢..
丹
答案 0 :(得分:3)
该行
header('Location: $url');
应该是
header("Location: $url");
不会在单引号内评估变量。
答案 1 :(得分:1)
如果你通过PHP的lint checker(php -l)运行你的代码,你会发现第62行(最后一行)有语法错误
你只是缺少需要关闭初始“if”语句的大括号。
答案 2 :(得分:0)
问题可能是
header('Location: $url');
exit();
尝试
header('Location: '.$url);
exit();
或
header("Location: $url");
exit();
# using the double quotes will parse the $url variable
答案 3 :(得分:0)
您是否只能在表单的操作属性中使用该网址并将方法设置为GET
?
<form action="https://portals.uk.rezlynx.net/DHPPORTAL/wfrmpakquery.aspx?SiteID=DHOLDHALL" method="get">
[...]
</form>