I just learn PHP. I tried to create a PHP which retrieves the types and then makes the Dropdown box. But I used the following code, the dropdown box is empty. Where is the error?
<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>