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 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C