I’m working on a forum software right now, and I’m doing the administration panel. I have a part with a dropdown box of all the current forums. It works, but it doesn’t show the first forum in the table.
This is my code
$select_forums = "SELECT id,name FROM forums";
$run_select_forums = mysql_query("$select_forums");
$row = mysql_fetch_array($run_select_forums, MYSQL_ASSOC);
<form action='index.php' method='post'>
<select>
<?php while ($row = mysql_fetch_array($run_select_forums, MYSQL_ASSOC)) { ?>
<option value="<?php echo $row["id"] ?>" name="selected"><?php echo $row["name"] ?>
</option>
<?php } ?>
</select><br/>
<input type='submit' name='submitdelete' value='Delete' />
</form>
Also I wondered how I can retrieve what item was selected from the list?
It isn’t displaying the first one because you’re calling
mysql_fetch_array()once before yourwhileloop begins:Additionally, you should wrap these values in
htmlentities()in the attributes andhtmlspecialchars()outside the attributes to escape them properly as HTML attributes (as well as against XSS attacks)I understand your
$row['id]is likely an integer not needing escaping, but it is a good habit to get into.