HI everyone, I am getting an undefined variable code:
Notice: Undefined variable: prod_options
Notice: Undefined variable: color_options
with this error it won't make my drop down option box show the list of colors or product.
What am I missing? Am I coding something wrong?
<?php
// manage colors
// pull associated color/products and display them
// give ability to delete associations and add
// Remove association
if(isset($_POST['submit']) && isset($_POST['attid'])){
$q = 'DELETE FROM color_list_attribute WHERE attributeid='.$_POST['attid'];
$r = mysql_query($q);
if($r !== false) echo '<h2>Color Product Association removed.</h2><br><br><br>';
}
// Add new color
if(isset($_POST['submit']) && isset($_POST['color'])){
$r =mysql_query('INSERT INTO color_list VALUES ("","'.$_POST['color'].'")');
if($r !== false) echo '<h2>New Color Added</h2><br><br><br>';
}
// Make association
if(isset($_POST['submit']) && isset($_POST['colorid'])){
$r= mysql_query('INSERT INTO color_list_attribute VALUES ("",'.$_POST['colorid'].','.$_POST['productid'].')');
if($r !== false) echo '<h2>Color Product Association Complete.</h2><br><br><br>';
}
// Display add new color
echo '<h2>Add new color</h2>';
?>
<form action="?content=colors" method="post">
<b>Color Name</b><input type="text" name="color" value=""><input type="submit" name="submit" value="Add Color">
</form>
<?php
// Display add color asccoiation
$q = 'SELECT description,prodid FROM products';
$r = mysql_query($q);
while($row = mysql_fetch_array($r))
$prod_options .= '<option value="'.$row['prodid'].'">'.$row['description'].'</option>';
$q = 'SELECT item_color,colorid FROM color_list';
$r = mysql_query($q);
while($row = mysql_fetch_array($r))
$color_options .= '<option value="'.$row['colorid'].'">'.$row['item_color'].'</option>';
?>
<br>
<h2>Color Product Associate</h2>
<form action="?content=colors" method="post">
<b>Product</b> <select name="productid"><?=$prod_options;?></select><br><b>Color </b><select name="colorid"><?=$color_options;?></select><br><input type="submit" name="submit" value="Associate">
</form>
<?php
// Display associations
$q = 'SELECT p.description, c.item_color, cp.attributeid FROM products p, color_list_attribute cp, color_list c WHERE cp.prodid = p.prodid AND cp.colorid = c.colorid ORDER BY p.description';
$r = mysql_query($q);
echo '<h2>Product Color Associations</h2>';
echo '<table><tr><td>Product</td><td>Color</td><td> </td></tr>';
while($row = mysql_fetch_array($r)){
echo '<tr><td>'.$row['description'].'</td><td>'.$row['item_color'].'</td><td><form action="?content=colors" method="post"><input type="hidden" name="attid" value="'.$row['attributeid'].'"><input type="submit" name="submit" value="Delete"></form></td></tr>';
}
echo '</table>';
?>