I'm trying to figure out the best way to do this, but I'm running into some problems.
I have a form that contains checkboxes. One of the checkbox options is Other: and then a text field. The checkboxes are created by a query to my dbtable "Colors_Menu":
function colors() {
$query = "SELECT * FROM Colors_Menu ORDER BY Color_Name ASC";
$result = @mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "<input type=\"checkbox\" name=\"colors[]\" value=\"{$row['Color_Name']}\">{$row['Color_Name']}
";
}
?>
<br />Add a color: <input type="text" name="colors[]">
<?
}
Now, I know that if I want all of these values stored as an array in my dbtable "Preferences", then I can use:
if (isset($_POST['colors'])) {
$colors=implode(',',$_POST['colors']);
} else {
$colors='FALSE';
echo '<font color="red">Please select at least one color</font>';
}
/* And then the query */
$query = "INSERT INTO Preferences (colors) VALUES ('$colors')";
But, in the case where a user fills in the "Other" text field, in addition to storing that value as part of the array (which, I believe this code will do), I also want it to add that color to the Colors_Menu table.
Now, I thought that maybe I could name the text field something different than "colors[]", and then just use an insert query to add the color to the Colors_Menu table. But, then I'm not sure how to go about "appending" the text field value to the colors[] array.
Can someone help me out here? I think I might be overcomplicating things?