1

When I am trying the code below, I get a blank dropdown. Is there anything wrong with this piece of code?

<?php
include ("Connect.php");

$db = new mysqli('localhost', $dbuser, $dbpass, $dbname);
?>
<div class="label">Select Customer Name:</div>
<select name="CustomerName">
<option value = "">---Select---</option>
<?php
$stmt = $db->prepare("SELECT `CustomerName` FROM `tafileuploadmappinghistory`");
$stmt->execute();
$stmt->bind_result($name);
while ($stmt->fetch()){
    echo "<option value='$name'></option>";
}
$stmt->close();
?>
</select> 
2
  • 2
    Your missing text value in option element <option value='$name'>$value</option> Commented Oct 25, 2018 at 8:20
  • Oh! Wow. Thank you Commented Oct 25, 2018 at 8:34

2 Answers 2

1

Just update this one line from

echo "<option value='$name'></option>";

to

echo "<option value='$name'>$name</option>";
Sign up to request clarification or add additional context in comments.

Comments

0

use this code in while loop for fetch your data

while($stmt->fetchAll()) {

 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.