答案 0 :(得分:0)
将表单操作设置为$_SERVER['PHP_SELF']
,如下所示:$_SERVER['PHP_SELF']
是PHP
super global variable
,它返回当前正在执行的脚本的filename
。
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="category" >
<option value="nocategory">No Category</option>
<option value="toyota">Toyota</option>
<option value="nissan">Nissan</option>
<option value="mazda">Mazda</option>
<option value="volvo">Volvo</option>
</select>
<input name="submit" value="Search" type="submit">
</form>
<?php
if (isset($_POST['submit'])){
$category = $_POST['category'];
echo $category;
}
?>
答案 1 :(得分:0)
使用此:
$selectoption = $_POST['category'];
<select name="category" >
<option value="nocategory">No Category</option>
<option value="toyota">Toyota</option>
<option value="nissan">Nissan</option>
<option value="mazda">Mazda</option>
<option value="volvo">Volvo</option>
</select>
$ selectoption 会存储所选类别的值