douyiyang6317 2012-04-16 17:47
浏览 56
已采纳

MySQL字段名称进入PHP下拉菜单

I have a web page where you can add new users onto the system. One of the values that gets added to the database is an account type value which selected from a PHP drop down menu with values from a MySQL database. The problem that I am having is that when I try to add a record from the dropdown menu the value is always 'undefined', where as it should be the value that is selected (e.g. If Account Type 'Test' is selected, 'Test' should be the value inserted into the database)

Here is my code if anybody can help me with this problem:

mysql_connect('localhost', 'username', 'password');

mysql_select_db('databasename');

$sql="SELECT Id, AccountName FROM tblaccounts";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["Id"];
    $accname=$row["AccountName"];
    $options.="<OPTION VALUE=\"$id\">".$accname.'</option>';

}

Displaying the dropdown:

<div class="cp-controls-lrg left">

    <p class="controls-margin">Account</p>

        <select name="sel-account-name" id="sel-account-name" class="cp-controls-sml input-select input-select-xxlrg" tabindex="6">

        <option value="0">Select Account
             <?php echo $options?>

        </select>

 </div>

Let me know if you need any additional code to find out what the problem is, Many thanks!!

  • 写回答

1条回答 默认 最新

  • duancaozen6066 2012-04-16 17:50
    关注

    You need to close the option in your HTML:

    <option value="0">Select Account</option>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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