triphis Posted November 7, 2003 Share Posted November 7, 2003 Okay, so I have a database with 2 columns: name, and status. It\'s basically for a collection I have. I want to run that info through a loop, and be able to check off the ones I have. I\'ve managed this before using radio buttons, and having a new form for EACH item in my collection... but is there anyway to loop out one big form using checkboxes and 1 submit button? I\'m quite good with forms and PHP usully, but whatever I try for this, doesn\'t work :[ Thanks This is what I used before (the radio buttons, and seperate submit buttons): [php:1:477a06f548]<?php $db = mysql_connect(\"localhost\", \"******\", \"******\"); mysql_select_db(\"*****_uk_db\",$db); $q=\"SELECT name FROM items WHERE status=0 ORDER BY name ASC\"; $result = mysql_query($q,$db); while ($row = mysql_fetch_array($result)) { $name = $row[\"name\"]; ?> <form action=\"form.php?name=<?=$name?>\" method=\"post\"> <INPUT TYPE=\"radio\" NAME=\"<?=$name?>\" VALUE=\"1\"><br><br><input type=\"submit\" name=\"submit\" value=\"Go!\"> </form> <?php } ?> [/php:1:477a06f548] I will post the process page if needed. Quote Link to comment https://forums.phpfreaks.com/topic/1315-entering-to-a-mysql-db-using-checkboxes/ Share on other sites More sharing options...
Barand Posted November 7, 2003 Share Posted November 7, 2003 1. Put form header and footer tags outside the loop. 2. use checkboxes, not radio for multiple selections 3. give checkboxes an array name, such as \'chbox[]\' [php:1:e8777ed79c] <form action=\"form.php>\" method=\"post\"> <?php while ($row = mysql_fetch_array($result)) { $name = $row[\"name\"]; ?> <INPUT TYPE=\"checkbox\" NAME=\"chbox[]\" VALUE=\"<?=$name?>\"> <?=$name?><br> <?php } <br> <input type=\"submit\" name=\"submit\" value=\"Go!\"></form> ?>[/php:1:e8777ed79c] Only checked checkboxes will be POSTed To find which ones when processing the form [php:1:e8777ed79c]<?php $chkboxes = $_POST[\'chbox\']; # $chkboxes is now an array of the posted names foreach ($chkboxes as $name) { # process then posted $names } ?>[/php:1:e8777ed79c] hth Quote Link to comment https://forums.phpfreaks.com/topic/1315-entering-to-a-mysql-db-using-checkboxes/#findComment-4371 Share on other sites More sharing options...
triphis Posted November 7, 2003 Author Share Posted November 7, 2003 Ohh, okay, i think I get it Barand: So then, on the process page, it will only take the $name variables, and I can do something like this: $q="UPDATE table SET status=1 WHERE name=$name"; I think thats right o.O; I\'ll go try it ^^ Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/1315-entering-to-a-mysql-db-using-checkboxes/#findComment-4373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.