我在整个互联网上寻找这个特定问题的答案,但似乎找不到。基本上,我有一组单选按钮和一个下拉列表,您可以从中选择选项。
<form method="get" action="phpindex.php">
<select name="season">
<option value="">- Season -</option>
<option value="spring">Spring</option>
<option value="summer">Summer</option>
<option value="fall">Fall</option>
<option value="winter">Winter</option>
</select>
<br /><br />
<input type="radio" name="beer" value="heavy"/>Heavy
<br />
<input type="radio" name="beer" value="light"/>Light
<br />
<input type="submit" OnClick="show_alert"/>
</form>
根据您的选择组合,您会在单击提交按钮时获得要回应的特定声明。例如,如果您选择春天作为季节,并选择浓啤酒,则应根据这些选择回应声明。问题是,回声功能不起作用,我认为这是因为单选按钮和下拉列表的组合。这是我的 PHP 和前面提到的 echo 函数不起作用。
<?php
$beer = $_GET["beer"];
$season = $_GET["season"];
$spring = $_GET["sp"];
$summer = $_GET["summer"];
$fall = $_GET["fall"];
$winter = $_GET["winter"];
$heavy = $_GET["heavy"];
$light = $_GET["light"];
if ( in_array("spring", $season) && in_array("heavy", $beer) ) {
echo "$state Bud"; }
if ( in_array("spring", $season) && in_array("light", $beer) ) {
echo "$state Abita"; }
if ( in_array("summer", $season) && in_array("heavy", $beer) ) {
echo "$state Yuengling"; }
if ( in_array("summer", $season) && in_array("light", $beer) ) {
echo "$state Coors"; }
if ( in_array("fall", $season) && in_array("heavy", $beer) ) {
echo "$state PBR"; }
if ( in_array("fall", $season) && in_array("light", $beer) ) {
echo "$state Miller"; }
if ( in_array("winter", $season) && in_array("heavy", $beer) ) {
echo "$state Natty"; }
if ( in_array("summer", $season) && in_array("light", $beer) ) {
echo "$state Kona"; }
$state = "Well, it looks like it's $season, and you want a $beer beer, so try this brew out:";
?>
任何帮助,将不胜感激!