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条)

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导