dongtuo4132 2013-11-07 17:20
浏览 6
已采纳

使用$ _POST将所选项目值发送到服务器

i have a dropdown and the items of the dropdown Filling dynamic, i looking for a way to send selected value to server using php not ajax i have a <form> and submit button, have to access the selected value on server, this is my code:

<form action="singer.php" method="post">
  <table>
    <tr>
      <td>سبک</td>
      <td><select name="genre_list">
          <?php
  include('../db_inc.php');
$sql="select * from genre";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_object($result)){
    $option =$row->genre_name;
    $value =$row->genre_id;
    echo '<option value='.$value.'>'.$option.'</option>';

    }
?>

        </select></td>

  </table>
</form>

i'm googled this issue but i can't find the solution,

  • 写回答

3条回答 默认 最新

  • donglu8334 2013-11-07 17:27
    关注

    If you submit to the current file, you will see the selected form by using $_POST['genre_list']

    If you want to send the user selected value, you should check where does $_POST['genre_list'] appears at the while-loop and then add to his <option> the attribute selected="selected" so it should look like

    $isSelected = ($_POST['genre_list'] == $row['COLUMN-NAME'] ? "selected='selected' " : "");
    echo '<option $isSelected value='.$value.'>'.$option.'</option>';
    

    Do not forget to avoid SQL-Injection when getting values from user client.

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

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题