dongwujie7477 2015-01-04 10:41
浏览 11
已采纳

无法从PHP中的html获取下拉列表值

My first php code gets the values from the table "mytable" which are January, February and March respectively. It works well, I could see Month,January,February and March inside the drop down list. My problem is within the second php code, when I click the search button, nothing happens. What I expected it to do was print out the value from the drop down list but sadly, I get nothing.

<select name="monthchoice">
<option value="">Month</option>; 

<?php   
$request="SELECT date FROM mytable WHERE username='qwe'";
$result=mysqli_query($con, $request);
while($fetch = mysqli_fetch_assoc($result))
{
echo '<option value="'.$fetch['date'].'">'.$fetch['date'].'</option>'; 
}
?>

</select>
<input type="submit" value="Search" name="submit"/>

<?php
if(isset($_POST["submit"]))
{
    if(!empty($_POST['monthchoice']))
        {
        $monthchoice1=$_POST['monthchoice'];
        echo "<br>";
        echo $monthchoice1;
        }
    else
        {
        echo "<br>";
        echo 'Please choose a month!';
        }
}
?>
  • 写回答

2条回答 默认 最新

  • doushi1473 2015-01-04 10:47
    关注

    Have you wrapped your select and input inside a form tag with method post?

    <form action="" method="post">
    <select name="monthchoice">
    <option value="">Month</option>; 
    
    <?php   
    $request="SELECT date FROM mytable WHERE username='qwe'";
    $result=mysqli_query($con, $request);
    while($fetch = mysqli_fetch_assoc($result))
    {
    echo '<option value="'.$fetch['date'].'">'.$fetch['date'].'</option>'; 
    }
    ?>
    
    </select>
    <input type="submit" value="Search" name="submit"/>
    
    <?php
    if(isset($_POST["submit"]))
    {
        if(!empty($_POST['monthchoice']))
            {
            $monthchoice1=$_POST['monthchoice'];
            echo "<br>";
            echo $monthchoice1;
            }
        else
            {
            echo "<br>";
            echo 'Please choose a month!';
            }
    }
    ?>
    
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗