PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am having problems saving all the boxes checked into my data base. I am pulling a list of check box values from a data base, then trying to get the boxes that are checked put back into a different table. I am able to get the form to add the last one checked, but I can't get multiple entries. I have never been very good at getting info into arrays. I assume that's what I need to do, is get all the values from the checked boxes into an array, then do a foreach and add them to a table.
Here's what I have so far. It isn't much.
while($row = mysql_fetch_array($result)){
$value_id=$row["value_id"];
$value_name= $row["value_name"];
echo"<input type=\"checkbox\" value=\"$value_name\" name=\"group_value\">$value_name";
}
$query = "INSERT INTO ".$prefix."store_options_".$group." set value='$group_value'";
$result = mysql_query($query) or die("Error: " . mysql_error());
<?php
while ($row = mysql_fetch_assoc($result)) {
// you don't really need temporary variables for variables you only
// use once
// you need to change the name of the checkboxes to group_value[] so
// that all the selected options will be entered into an array
// surely you want the value to be the id and not the name?
echo '<input type="checkbox" value="'.$row['value_id'].'" name="group_value[]"> '.$row['value_name'];
}
?>
Do each of the values go into a separate row in the other table or what?
I found the info on adding the [] after the group_name last night to make them into an array. I can't believe it was that easy. Well, actually I can. =)
Do each of the values go into a separate row in the other table or what?
Yes they are. That's why I want to use the name rather than the id.