尝试这样做,但它只回显了实际上没有选择.php文件包含在同一页面中的值。代码如下......
<body>
<form name="form1" method="POST" action="test.php">
<select name="select" onChange="document.form1.submit()">
<option selected>Select an Industry</option>
<option value="members">members</option>
<option value="Female">Female Members</option>
</select>
</form>
<?php
$file = $_POST['select'];
echo $file;
$path_file = $_SERVER['DOCUMENT_ROOT']/$file.php;
if(file_exists($path_file))
{
echo("The file does not exist at: $path_file");
}
else
{
require_once($path_file);
}?>
</body>
一旦排序,我希望它将包含一个php文件到同一页面!在更改之前还需要一个默认页面,所以会员是主页面,然后人们可以选择女性来看女性等。
答案 0 :(得分:1)
更改
$path_file = $_SERVER['DOCUMENT_ROOT']/$file.php;
到
$path_file = $_SERVER['DOCUMENT_ROOT']."/".$file.".php";
但这对安全性来说非常糟糕(你不能信任_POST数据)。更好地改变:
if (isset($_POST['select']) && $_POST['select'])
{
if ($_POST['select'] == 'something')
include 'something.php';
if ($_POST['select'] == 'somethingelse')
include 'another.php';
} else {
include 'default.php';
}