Hi Guys
I have created a form that will allow me to enter products in. But I have got a couple of drop down boxes that I would like it to get the data from a MySQL DB.
Below is the code for the drop down box
<select name="vendorName" id="vendorName">
<?php
include ('includes/populate_vendors.php');
?>
</select>
I was reading somewhere on a forum that I could use an include file that has the sql code that grabs the data from the MySQL DB.
The table is called: vendors
Fields are: vendorID & vendorName
What I want is when I click on the drop down box it shows the list of vendors that I can choose to assocaite with that product.
Can anyone help me out here.
I have some code below that doesn't work but it may give you and idea
<?php
$server = "localhost";
$user = "matthew";
$pass = "";
$conn = mysql_connect($server,$user,$pass) or die(mysql_error());
mysql_select_db ("rcex_computers") or die(mysql_error());
$pop_query=mysql_query("SELECT * FROM vendors ORDER BY vendorName ASC");
if(isset($ex_catId)){//START Vendors
$ex_cat_query=mysql_query("SELECT * FROM vendors WHERE vendorId='$ex_catId' LIMIT 1");
$ex_cat_data=mysql_fetch_assoc($ex_cat_query);
$ex_category = $ex_cat_data['vendorName'];
?>
<option value="<?php echo $ex_catId;?>" selected><?php echo $ex_category;?></option>
<?php
}//END EX CATEGORY
while ($data = mysql_fetch_assoc($pop_query))
{
echo "<option value=\"";
echo $data['vendorId'];
echo "\">";
echo $data['vendorName'];
echo "</option> \n";
}
?>