0

I trying make a combobox with php and mysql but i cant find a solution. How I can fix this code?

$conn = new mysqli($servername, $username, $password, $db);
$result = mysqli_query($conn, "SELECT * FROM exemple") or die (mysqli_error($conn));
?>
<form action="" method="post">
  <h1>Combo</h1>
    <select name="cbx" id="cbx">
    <?php while($ri = mysql_fetch_array($result)) { ?>
      <option value="<?php echo $ri['exemp'] ?>">
        <?php echo $ri['exemp2'] ?>
      </option>
    </select>
    <?php } ?>
</form>
2
  • what is $result ?! please post all the code related to your issue. Commented Mar 28, 2019 at 15:24
  • 1
    Hi, @Kalil Alves, since you are new here, I recommend you reading "How to create a Minimal, Complete, and Verifiable example". You will get better feedback by following those tips. Commented Mar 28, 2019 at 15:29

1 Answer 1

1

Simply, close while loop before </select> tag:

<form action="" method="post">
  <h1>Combo</h1>
  <select name="cbx" id="cbx">
    <?php while ($ri = mysql_fetch_array($result)) { ?>
    <option value="<?php echo $ri['exemp'] ?>"><?php echo $ri['exemp2'] ?></option>
    <?php } ?>
  </select>
</form>
Sign up to request clarification or add additional context in comments.

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.