I'm making a dropdown list populated with all productnames from a pricelist (table), where users can select a product, and hit the button to proceed to a page that displays product details and price.
Works like a charm - except for ONE small problem: the first product in the table doesn't appear on the dropdown list, it starts out with a empty line.
If you select the empty line, you get a
-You have an error in your SQL syntax near '' at line 1- message on the next page, all the others work perfect....
I'm confused here - can anyone help??
PHP Code:
<?php
//connect
$db = mysql_connect("host", "user", "password");
mysql_select_db("database", $db);
// We have now connected, unless you got an error message
//get ID and item from table
$query_art = "SELECT ID, art FROM prices";
$art = mysql_query($query_art) or die(mysql_error());
$row_art = mysql_fetch_row($art);
?>
<!--sends ID from selected item to display.php-->
<form name="form" method="post" action="display.php">
<select name="fieldOne">
<option value="">Velg artikkel</option>
<?php
//insert item into dropdown with ID as value
do
{
?>
<option value="<?php echo $row_art['ID']?>"><?php echo $row_art['art']?></option>
<?php
}
while ($row_art = mysql_fetch_assoc($art));
?>
</select>
<input type="submit" name="Submit" value="Finn prisen" >
</form>