我是 PHP 新手,正在尝试获取从 select 标签中选择的选项的值。我熟悉某些类型的输入,例如单选、文本、复选框等。我的问题是“类型”是从选择标签中选择的选项。前三种形式工作得很好,但第四种则不行
这是我的代码
<form action = display.php method="get">
input first name:
<input type=text name=fname><br>
input last name:
<input type=text name=lname><br>
<input type=submit value="Click">
</form>
<form name="input"
action=radio.php method="get">
Username:<input type="text" name="user">
<br>
<input type=radio name=card_type value="visa ">
Visa <br>
<input type=radio name=card_type value="mc">
Master Card <br>
<input type="radio" name=card_type value="discover">
Discover <br>
<input type="submit" value="Submit"/>
</form>
<form name="gender"
action=gender.php method="get">
<input type=radio name=gender_type value="male">
Male <br>
<input type=radio name=gender_type value="female">
Female <br>
<input type="submit" value="Submit"/>
</form>
<form name="chosen_party" action=party.php method="get">
<select>
<option type=text name=party_type value="democrat">Democrat</option>
<option type=text name=party_type value="republican">Republican</option>
<option type=text name=party_type value="independent">Independent</option>
<option type=text name=party_type value="undecided">Undecided</option>
</select>
<input type=submit value="Submit">
</form>
以及第四种形式的 PHP 文件...
<?php
$party_select = $_GET['party_type'];
echo "User has chosen $party_select";
?>
首先为选择标签命名。如果是选项,则为每个选项赋予一个值。像这样..
<form name="chosen_party" action=party.php method="get">
<select name="party_type">
<option value="democrat">Democrat</option>
<option value="republican">Republican</option>
<option value="independent">Independent</option>
<option value="undecided">Undecided</option>
</select>
<input type=submit value="Submit">
</form>
然后在php中存在一点语法问题。您必须将 $party_select 放在引用之外。代码应该是..
<?php
$party_select = $_GET['party_type'];
echo 'User has chosen '.$party_select;
?>
希望这可以帮助..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)