Here is a quickie obviously unworking code of an example of what I am looking to do.
Lets say this is a dinner menu, and the echo’s are currently all the foods that are stored in the database. The user selects only the foods they want, and those selections are inserted into another table.
EXAMPLE:
<form method="post" action="entryform3.php">
<?php
SELECT * FROM foods ...etc...etc...
//Say for example whats echoed below at the moment is value: pizza, apple, steak...etc. So this will echo atleast 3 entries.
echo "For dinner, I'd like ". $result['food'] ."?";
echo "<input type=\"checkbox\" name=\"check\" />Click Me<hr></input>";
echo "<input type=\"hidden\" name=\"item_name\" value=\"$result['food']\"/>";
?>
<input type="submit" value="Add Selected Foods" name="submit"></form>
------------entryform3.php-----------
<?php
$food = $_POST['food'];
if (isset($_POST['check'])) {
INSERT INTO selectedfoods "(foods) VALUES '$food'";
}
//made up example... but if user check marks only apple, and steak from the echo, I want only apple and steak to be inserted into database.
?>
I realize there is missing mysql and such, but my problem lies in tying together the checkbox button with an individual value. My partially working code that I took this example from, only takes the very last echoed selection, if any one of the foods is checked.
So, it doesn’t send the correct food choice into the database, only the last echoed –the if statement only notices if any one of the check boxes are selected or not.
Thanks!
It seems like you miss the name of the checkbox as array. For example, you may write your checkbox like this:
then when you get the result, just do like this: