dhimok Posted June 8, 2007 Share Posted June 8, 2007 Hi every one. I have this form and i want to do a multiple insert using checkboxes. The values are fetched from a tbl1 and will be inserted into another table tbl2. I want to get only those fields where checkbox next to it is selected <form> <?php $sql = mysql_query("Select id, field FROM tbl1"); while(list($id,$field) = mysql_fetch_array($sql)) { echo ' <p> <input type="checkbox" name="selected_flds[]" value="'.$id.'" /> <input type="text" name="field[]" value="'.$field.'" /> </p> '; } // end while ?> </form> thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/54753-multiple-insert-or-update/ Share on other sites More sharing options...
unidox Posted June 8, 2007 Share Posted June 8, 2007 So you want more than one checkbox? Quote Link to comment https://forums.phpfreaks.com/topic/54753-multiple-insert-or-update/#findComment-270776 Share on other sites More sharing options...
dhimok Posted June 8, 2007 Author Share Posted June 8, 2007 Yeah. Insert all with checkbox checked Quote Link to comment https://forums.phpfreaks.com/topic/54753-multiple-insert-or-update/#findComment-270778 Share on other sites More sharing options...
unidox Posted June 8, 2007 Share Posted June 8, 2007 I am a bit confused, but what do you want? Just add another line? <input type="checkbox" name="selected_flds[]" value="'.$id.'" /> Quote Link to comment https://forums.phpfreaks.com/topic/54753-multiple-insert-or-update/#findComment-270779 Share on other sites More sharing options...
dhimok Posted June 8, 2007 Author Share Posted June 8, 2007 As you can see from the above code I am looping thru records and the form will look like this: <form> <p> <input type="checkbox" name="selected_flds[]" value="1" /> <input type="text" name="field[]" value="field1" /> </p> <p> <input type="checkbox" name="selected_flds[]" value="2" /> <input type="text" name="field[]" value="field2" /> </p> <p> <input type="checkbox" name="selected_flds[]" value="3" /> <input type="text" name="field[]" value="field3" /> </p> .... etc. </form> I would do something like this: <?php foreach ($_POST['selected_flds'] as $key => $value) { // update where id=$value } ?> But this updates all records. I want only with checkboxes checked. So here I am stuck Quote Link to comment https://forums.phpfreaks.com/topic/54753-multiple-insert-or-update/#findComment-270797 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.