papaface Posted December 14, 2006 Share Posted December 14, 2006 Hello,I was wondering if someone can help me.Currently I have the following code in a file named submit.php:[code]<?phprequire("includes/connect.php");require("includes/selectdb.php");?> <form action="process.php" method="post"> <?php $sql = mysql_query("select id,name from groceries",$con); while (list($id,$name) = mysql_fetch_array($sql)) {?> <label><?=$name?><input name="<?=$id?>" type="checkbox" value="<?=$name?>"></label><br> <?php } ?> </form>[/code]How would I go about adding the values of an unlimited amount of checkboxes to a database? Link to comment https://forums.phpfreaks.com/topic/30698-add-data-to-database-checkboxes/ Share on other sites More sharing options...
JasonLewis Posted December 15, 2006 Share Posted December 15, 2006 make an array out of it... like so:[code]<?phprequire("includes/connect.php");require("includes/selectdb.php");if(!isset($_POST['submit'])){?> <form action="process.php" method="post"> <?php $sql = mysql_query("select id,name from groceries",$con); while (list($id,$name) = mysql_fetch_array($sql)) {?> <label><?=$name?><input name="groceries[]" type="checkbox" value="<?=$name?>"></label><br> <?php } ?><input type="submit" value="Process" name="submit"> </form><?php}else{ //they have submitted the form$groceries = $_POST['groceries'];echo "Selected Groceries:<ul>";for($i = 0; $i < count($groceries); $i++){echo "<li>".$groceries[$i]."</li>";}echo "</ul>";}?>[/code]of course you can change the echoing out the groceries to making a query out of it... BUt hopefully that is what you are after... Link to comment https://forums.phpfreaks.com/topic/30698-add-data-to-database-checkboxes/#findComment-141466 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.