如何使用php从mysql db中显示<select>中的值?

时间:2015-09-25 13:46:38

标签: php mysql select drop-down-menu

我在php中有一个表单,我需要使用php从DB(phpmyadmin)中选择值。当我添加我的代码时它不起作用。有人可以查看这段代码吗?     &lt; form role =“form”action =“test.php”enctype =“multipart / form-data”method =“post”accept-charset =“utf-8”&gt;     &lt; div class =“form-group”&gt;       &lt; label for =“name”&gt;名称:&lt; / label&gt;       &lt; input type =“text”class =“form-control”name =“name”id =“name”placeholder =“Enter Category Name”&gt;     &LT; / DIV&GT;     &lt; div class =“form-group”&gt;       &lt; label for =“code”&gt;代码:&lt; / label&gt;        &LT;选择&GT;       &LT; PHP / *将字符集更改为utf8 * /         if(!mysqli_set_charset($ conn,“utf8”)){             printf(“加载字符集错误utf8:%s \ n”,mysqli_error($ conn));             出口();         } else {             $ rslt = mysqli_query($ con,“SELECT * from category”)或die(mysqli_error($ conn));         }         while($ row = mysql_fetch_array($ rslt)){               echo $ row;                 echo“&lt; option value = \”owner1 \“&gt;” 。 $ row ['code']。 “&LT; /选项&gt;” 中;         }     ?&GT;         &LT; /选择&GT;     &LT; / DIV&GT;      &lt; div class =“form-group”&gt;       &lt; label for =“rank”&gt; Rank:&lt; / label&gt;       &lt; input type =“text”class =“form-control”name =“rank”id =“rank”placeholder =“Enter Category Rank”&gt;     &LT; / DIV&GT;     &lt; div class =“form-group”&gt;       &lt; label for =“tag”&gt;标签:&lt; / label&gt;       &lt; input type =“text”class =“form-control”name =“tag”id =“tag”placeholder =“Enter Category tag”&gt;     &LT; / DIV&GT;     &lt; button type =“submit”class =“btn btn-default”&gt; Done&lt; / button&gt;   &LT; /形式&GT;

1 个答案:

答案 0 :(得分:2)

从评论中继续前进,这就是所需要的:

而不是:

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

应该是:

while($row = mysqli_fetch_assoc($rslt){
  

注意:还有一些其他警告。但如果你这只是   关心。欢呼声