Page 1 of 1

Populating drop down box

Posted: Wed Jul 21, 2010 6:31 am
by ccherif007
I am trying to populate a drop down box from mysql database but for some reason i am getting nothing there are no errors
here is my code

<?php
$con = mysql_connect("localhost","dbuname","tdbpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("DBname", $con);
echo "<select name=Store Location=''>Store Location</option>";
$query = "SELECT StoreLocation FROM Stores";
$result = mysql_query($query);
echo "<select name =stores value=''>loaction</Option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[Storelocation]></option>";

}
echo "</select>";
/*while($row = mysql_fetch_array($result))
{
echo "<option value=$row[StoreLocation]></option>";
echo "</select>";
}*/
mysql_close($con);

?>

any help is apreciated thanks in advance

Re: Populating drop down box

Posted: Wed Jul 21, 2010 10:20 am
by eruna
First, to return errors use this:
$result = mysql_query($query) or die(mysql_error()." LINE:".__LINE__);

Second thing:
$nt[Storelocation] should be $nt['Storelocation'] (quotes around "Storelocation")

To see what you have in your variables use:
print_r($nt);

This way you can check if there is anything being returned or if you've misspelled a variable.

E