1

Been at this for a bit and I cannot figure out what is wrong. I am trying to output a mySQL query into a drop down (just using PHP). The dropdown works, but there are no values in the list. However, it does seem to be aware of how many rows are in the table. Please advise. Thanks!

<html>
<head>
<body>

<table border="1">


<?php
require_once ('includes/database.php');         

$query = "SELECT User_ID FROM User_Account";
$result = mysqli_query ($my_dbhandle, $query);
echo "<select name=dropdown value=''>Dropdown</option>";
while($r = mysqli_fetch_array($result)){
echo "<option value=" . $r['User_ID'] . ">" . $r['User_ID'] . "</option>";
}
echo "</select>";



mysqli_close($my_dbhandle);
?>

</table>
</body>
</head>
</html>
3
  • For one thing, <select> does not have value, only <option>. Plus you should quote things, that's why it's not working. View HTML source. Commented Apr 11, 2015 at 16:32
  • Plus, your other question already contains your solution for this. Just do the same for the option echo. Commented Apr 11, 2015 at 16:38
  • Thanks, @Fred-ii-. I got it going :) Commented Apr 11, 2015 at 16:42

1 Answer 1

2

You forgot to add the actual text. So this:

"<option value=$r[User_ID]></option>";

should be this:

"<option value=" . $r['User_ID'] . ">" . $r['User_ID'] . "</option>";

If User_ID is in any way editable by users, you also should add protection against XSS.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @tim. That was it. I will mark it correct ASAP.

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.