CassidyHunt
IS-IT--Management
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:
Any help would be greatly appreciated.
Thanks
Cassidy
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