如何填充下拉菜单?

时间:2019-04-06 02:18:58

标签: php

我只是学习PHP。我试图创建一个PHP,该PHP检索类型,然后创建Dropdown框。但是我使用了以下代码,下拉框为空。错误在哪里?

 <select name="type">
 <option value="" selected>-- Select One --</option>
<?php
$conn = mysqli_connect('localhost','root','','phplab2' );

if (!$conn) { 
     $errorMsg = mysqli_connect_error($conn);
     exit('could not connect to database'. $errorMsg); 
}
$query = "select type from product where type = ? ";
$pStmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($pStmt,'s', $type);
mysqli_stmt_execute($pStmt);
mysqli_stmt_bind_result($pStmt, $type_r);
while(
mysqli_stmt_fetch($pStmt))
{   
print '<option value='.$type.'>'.$type.'</option>';
}

mysqli_stmt_close($pStmt);
mysqli_close($conn);

?>
 </select><p></p>

0 个答案:

没有答案