【发布时间】:2023-04-08 14:28:01
【问题描述】:
真的很难让我的表单允许用户根据他们选择的单选按钮访问 URL。当我在我的服务器上完成表单时,它会按预期重定向到专用 URL,但是它说找不到对象并且还说“在此服务器上找不到请求的 URL”。我真的不明白如何将文件保存到网站 URL 的 htdocs 文件夹中。用户可能被重定向到的网站选项如下:
http://www.nisra.gov.uk/demography/default.asp28.htm
http://www.ons.gov.uk/ons/rel/vsob1/baby-names--england-and-wales/index.html
以下是我的代码:
PHP:
<?php
if (isset($_GET['location']))
{
$location = $_GET["location"];
if ($location === "S"){
header("Location: http://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/vital-events/names/babies-first-names");
} else if ($location === "EW")
{
header("Location: http://www.ons.gov.uk/ons/rel/vsob1/baby-names--england-and-wales/index.html");
} else if ($location === "NI")
{
header("Location: http://www.nisra.gov.uk/demography/default.asp28.htm");
}
}
?>
HTML:
<!DOCTYPE html>
<head>
<title>Baby Name Popularity Tables</title>
</head>
<body>
<h1>Baby Name Popularity Tables</h1>
Please select either England and Wales, Scotland or Northern Ireland.
<form action="" method="get">
<table>
<tr>
<td><input type="radio" name="location" value="EW"/></td>
<td>England & Wales</td>
</tr>
<tr>
<td><input type="radio" name="location" value="S"/></td>
<td>Scotland</td>
</tr>
<tr>
<td><input type="radio" name="location" value="NI"/></td>
<td>Northern Ireland</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Get Baby Names"/></td>
</tr>
</table>
</form>
</body>
</html>
任何帮助将不胜感激。
【问题讨论】:
标签: php html forms redirect xampp