elpaisa Posted January 24, 2008 Share Posted January 24, 2008 Hi all! Here is my problem. I have a table called meds, and i want to insert records from different checkboxes with the same name but different values this is the structure of table id pharid imageid Now, the checkbox is the next <input type="checkbox" name="imageid[]" value="'.$images['imageid'].'" > <b>'.$images['title'].'</b> Well there are various checkboxes in the form dinamically generated from a query to another table, and i need to insert one record with imageid values into the field imageid of the table per each checkbox , and pharid that is from another var be inserted the same on each record. Thnx all! Help is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/ Share on other sites More sharing options...
teng84 Posted January 24, 2008 Share Posted January 24, 2008 sorry can you tell us your question? Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448369 Share on other sites More sharing options...
elpaisa Posted January 24, 2008 Author Share Posted January 24, 2008 sorry if i am not clear what i really, really need is to insert each checkbox value into the table one record per each, the checkboxes are dinamically generated by a while loop and all has the same names but different values. so i don't know how to do this, becouse it has the same name it only inserts one record, all your need will be appreciated, if i don't explain very well is becouse i don't write english very well... so be patient, here is my code Checkbox <input type="checkbox" name="imageid[]" value="'.$images['imageid'].'" > <b>'.$images['title'].'</b> $imageid = $_POST['imageid'][]; $pharid = $_POST['pharid']; if($imageid) { foreach($_POST['imageid'] as $i) { $DB->query("INSERT INTO meds (medid, pharid, imageid) VALUES('NULL', '$pharid', '$imageid[$i]')"); } } Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448379 Share on other sites More sharing options...
teng84 Posted January 24, 2008 Share Posted January 24, 2008 // Check if button name "Submit" is active, do this if(count($_POST['imageid']<=0) { foreach($_POST['imageid'] as $key => $value) { $DB->query("INSERT INTO meds (medid, pharid, imageid) VALUES('NULL', '$pharid', '$value')"); } } that should work but the problem there is that $pharid' is always the same is that what you mean? and note.. I'm also bad in english see it from my avatar Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448386 Share on other sites More sharing options...
elpaisa Posted January 24, 2008 Author Share Posted January 24, 2008 Thanks man, and yes pharid will always be the same, i am testing the code, but it doesn't work, something in the sintax is bad becouse it blanks the page Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448391 Share on other sites More sharing options...
teng84 Posted January 24, 2008 Share Posted January 24, 2008 sorry this if(count($_POST['imageid']<=0) i missed ) make it if(count($_POST['imageid']<=0)) and turn your error reporting on ! Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448400 Share on other sites More sharing options...
elpaisa Posted January 24, 2008 Author Share Posted January 24, 2008 THANK, man your really helped, how i didn't realize, before it was exactly what i need, thanks again!. Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448402 Share on other sites More sharing options...
teng84 Posted January 24, 2008 Share Posted January 24, 2008 hehe i see my english is better that yours joke.. don't forget to mark this as solved Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448406 Share on other sites More sharing options...
elpaisa Posted January 25, 2008 Author Share Posted January 25, 2008 hey, do you know why the records in the key of the table are added unordered? Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448419 Share on other sites More sharing options...
teng84 Posted January 25, 2008 Share Posted January 25, 2008 what do you mean added unordered? Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448421 Share on other sites More sharing options...
elpaisa Posted January 25, 2008 Author Share Posted January 25, 2008 yes the ids are not autoincrementing ordered, the first i 5 the second is 3 the third is 4 etc... Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448428 Share on other sites More sharing options...
elpaisa Posted January 25, 2008 Author Share Posted January 25, 2008 but that's ok, i'm for now stuck in some other things, could you help me with them too? Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448434 Share on other sites More sharing options...
teng84 Posted January 25, 2008 Share Posted January 25, 2008 dont care if you it is not adding that way(sorted) you can query them and sort just the way you want! i can help if this is not that complected for free Quote Link to comment https://forums.phpfreaks.com/topic/87661-solved-insert-checkbox-values-one-record-per-each/#findComment-448439 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.