Populating drop down box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ccherif007
Forum Newbie
Posts: 1
Joined: Wed Jul 21, 2010 6:26 am

Populating drop down box

Post 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
eruna
Forum Newbie
Posts: 17
Joined: Mon Jun 28, 2010 2:02 pm

Re: Populating drop down box

Post 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
Post Reply