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>&nbsp;<select name="productid"><?=$prod_options;?></select><br><b>Color&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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>&nbsp;</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>';

?>

Before you append to a variable you need to first define it. Just add $prod_options = ''; and $color_options = ''; before their respective while statements.

Also, that is just a notice. Not really an error. You can get rid of them by changing error reporting settings.

Before you append to a variable you need to first define it. Just add $prod_options = ''; and $color_options = ''; before their respective while statements.

Also, that is just a notice. Not really an error. You can get rid of them by changing error reporting settings.

Keith thank you very much the undefine variable it is gone now. But the drop down box is still not displaying the content list.

Also for learning, you mention that notice are not really error. They are pretty much to help make cleaner code right? So does that mean notices does not do anything to the code from it to display wrong? Also I notice how you did the undefine variable with an empty string. Could I do that will all undefine varialbe or just keep

<?php

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
?>

this in my header.

sorry for the list of questions. I am learning as I go.

This article has been dead for over six months. Start a new discussion instead.