kenny22 Posted March 21, 2011 Share Posted March 21, 2011 Is it possible to have multiple check boxes on a single form and a single submit button tp post the values into different rows of DB Kenny Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 21, 2011 Share Posted March 21, 2011 Yes, of course. You would have to elaborate on "...post the values into different rows of DB" for us to provide any worthwhile advice. But, let's say, for example, that you want a page where you can "deactivate" records. So you would generate a page with a single check box for each record next to a tile for each record or some way for the user to identify which record is which. Now, you can decide to only include currently active records or include all record and check/uncheck each record according to it's current active status. For simplicity I will assume this will only include currently active records with the options to deactivate them. I have left of some necessary code - such as connecting to the db, validation/data cleansing, etc. Page to create form <?php //Run query to get list of currently active records $query = "SELECT * FROM table WHERE active = 1"; $result = mysql_query($query); //Create HTML form code to display checkboxes for each active record $formFields = ''; while($row = mysql_fetch_assoc($result)) { $formFields .= "<input type=\"{$row['id']}\" name=\"recID[]\" />{$row['name']}<br />\n"; } ?> <html> <body> <form action="deactivate.php"> Select the records to deactivate:<br /> <?php echo $formFields; ?> <button type="submit">Deactive Selected</button< </form> </body> </html> Page to process the form //Create id list from submitted values for query $idList = implode(', ', $_POST['ids']); //Create and run query to update records $query = "UPDATE table SET active = 0 WHERE id IN ({$idList})"; $result = mysql_query($query); Quote Link to comment Share on other sites More sharing options...
kenny22 Posted March 21, 2011 Author Share Posted March 21, 2011 Thanks for reply more info for you, the form pulls in a list of names from database and has a check box for each name, i want to be able to select 11 names by checking the boxes next to the names and submit the form so it enters the value '1' into a field for each name example: name1, 1 (check box selected) name2, 1 (check box selected) name3, 0 (check box not selected) kenny Quote Link to comment 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.