Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Select drop down boxes

Status
Not open for further replies.

CassidyHunt

IS-IT--Management
Jan 7, 2004
688
US
I have multiple drop down boxes that I am trying to fill dynamically from MYSQL. I can get the data and fill the first one but the second one I recieve this:
Notice: Undefined index: ddlCategories in c:\Inetpub\ on line 42

Followed promply by the data I requested from the database.

Here is my code:

Code:
<?php
$link = mysql_connect('localhost','webguest','P!@y3r1')
  or die('Could not connect: ' . mysql_error());
mysql_select_db('webdb') or die('Could not select database');

$query = 'select description from Years';
$result = mysql_query($query) or die('Query Failed: ' . mysql_error());
$num = mysql_numrows($result);

echo "<form method='Post' action='Searchtest.php'>\n";
echo "<select id='ddlYear' name='ddlYear'>\n";
$i = 0;
while ($i < $num)
{
$Years = mysql_result($result,$i,"description");
if($_POST['ddlYear'] == $Years)
{
  echo "\t<option value='" . $Years . "' selected>" . $Years . "</option>\n";
}
else
{
  echo "\t<option value='" . $Years . "'>" . $Years . "</option>\n";
}

$i++;
}



// Free resultset
mysql_free_result($result);

$query2 = 'select description from Categories';
$result = mysql_query($query) or die('Query Failed: ' . mysql_error());
$num = mysql_numrows($result);

echo "<select id='ddlCategories' name='ddlCategories'>\n";
$i = 0;
while ($i < $num)
{
$Categories = mysql_result($result2,$i,"description");
if($_POST['ddlCategories'] == $Categories)
{
  echo "\t<option value='" . $Categories . "' selected>" . $Categories . "</option>\n";
}
else
{
  echo "\t<option value='" . $Categories . "'>" . $Categories . "</option>\n";
}

$i++;
}
// Closing connection
mysql_close($link);

echo "</select>\n";
echo "<input type='submit' name='submit' id='submit'>\n";
echo "</form>";
?>

Any help would be greatly appreciated.

Thanks

Cassidy
 
Figured it out and feel like an idiot. Needed to put my closing tag for the drop down box back so I could close the first select.

Thanks

Cassiyd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top