I'm trying to populate a select box with rows from a table, but it's not showing up properly. I've looked at the source of the page, and it looks like the option html is not being outputted. Anyone spot what's wrong?

<h1>Upload Picture</h1>
    <form action="gallery.php" method="post">
    <label for="photo">Select file: </label><input type="file" name="photo" />
    <select name="photoGallery">
    $sql="SELECT * FROM tblgallery ORDER BY galleryId";
	while($row = mysql_fetch_array($result))
		print '<option value="'.$row['galleryId'].'">'.$row['name'].'</option>';
    <input type="submit" value="Upload photo"/>


Recommended Answers

All 3 Replies

Ok it seems to be "sort of" working now, not sure whether it was a cache issue.

My problem now is that the total rows in the table is 4, and the first row is being omitted.

Correct me if i'm wrong, but I think it might be because you're trying to print each row as an associative array when the results are returned as mysql_fetch_array.

Try this:

while($row = mysql_fetch_assoc($result))

I managed to get it working, I had another query running above that code to retrieve photos so the variables got mixed up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.