dongtao9095 2014-07-02 19:14
浏览 32
已采纳

从Double下拉菜单中选择PHP中的值

I am creating a drop-down menu in which the second drop-down is dependent upon the first; the first drop down is a list of table, and depending on what table you select, the columns of that table will be able to be selected.

<form id = "table_column" action = "file_name.php">
    <select id = "tables" name = "tables" onclick = "script();">
        <option name = "table_option_one" value = "people">people</option>
        <option>...</option>
    </select>
    <select id = "columns" name = "columns" onclick = "other_script();">
        <option name = "column_option_one" value = "name">name</option>
        <option>...</option>
    </select>
    <input type = "submit"></input>
</form>

I have tried the code below to no success.

$table_name = $_POST["tables"];
$column_name = $_POST["columns"];

How do I access the values selected in each drop-down menu in PHP?

I am only having a problem with the retrieval of the selected values. The menus depending on another and switching work fine

  • 写回答

3条回答 默认 最新

  • douyingmou1389 2014-07-02 19:34
    关注

    Okay, with your new clarification (you are populating the drop-downs fine), here is what you can do.

    Give the input tag an ID as such:

    <input type="submit" name="submit" id="submit" value="Submit"> <!--form submit button-->
    

    and in your PHP do a conditional as such:

    if (isset($_POST['submit'])) {
        $table_name = $_POST["tables"];
        $column_name = $_POST["columns"];
    }
    

    make sure your form also has the method="post" attribute as well:

    <form id = "table_column" action="file_name.php" method="post">
    

    That way when the submit button is hit, your values will be retrieved.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记