friedice Posted March 16, 2011 Share Posted March 16, 2011 for example i have a form like this <form name="input" action="page2.php" method="post"> <table cellpadding="20" width="100%"> <!-- BEGIN query --> <tr> <td> <img src="../eImages/{IMAGE}.jpg" style="width:200px;height:200px;" /> </td> <td> {EVENTTYPE}</br> {DPLACE} </br> {NAME}</br> {SPEAKERS}</br> {LOC}</br> {STREET}</br> {TIME} </br> </td> <td> <input type="checkbox" name="eventlist"> </td> </tr> <!-- END query --> </table> <input type="submit" value="Submit" /> </form> this is all dynamically loaded each time from a database so it could have several trs of this formal my goal is to only select 3 of them and then submit the form this is will make a checkbox for each one including all the details but the problem is that the checkboxes will all have the same name as oneanother is there a way to increment the checkbox name value each time it goes through the while loop in the database? thx Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/ Share on other sites More sharing options...
AbraCadaver Posted March 16, 2011 Share Posted March 16, 2011 Use an array: <input type="checkbox" name="eventlist[]"> But for these you'll probably want to identify them somehow, maybe with the event ID if there is one: <input type="checkbox" name="eventlist[{id}]"> Assuming that {something} are template tags for the PHP vars. Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1188291 Share on other sites More sharing options...
friedice Posted March 16, 2011 Author Share Posted March 16, 2011 hmm i was thinkin bout it along that line to use an array but wasnt sure i think i will use the ID for the identifier for each checkbox ya ur right its in pear templates if i were to post this page using the form, how would i end up grabin all the checkboxes (checked and unchecked) from the previous page and then insert them accordinly into the db thx Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1188447 Share on other sites More sharing options...
friedice Posted March 17, 2011 Author Share Posted March 17, 2011 and also save it in the database sayin each record is clicked or not since i need to retrieve only the clicked one on another page from the db Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1188928 Share on other sites More sharing options...
Eyewash01 Posted March 17, 2011 Share Posted March 17, 2011 Checkboxes are only posted across if they are actually checked. The best way to find them is to iterate through the post variables and find any occurences of the checkboxes. THE USER PAGE: <?php $sql = "SELECT p_id FROM products;": $rs = mysql_query($sql); while ($row = mysql_fetch_array($rs)){ extract ($row); echo '<input type="checkbox" name="fmCheck_'.$p_id.'" id="fmCheck_'.$p_id.'" value="'.$p_id.'" />'; } ?> PHP PROCESSING PAGE: <?php foreach($_POST as $key => $value){ if (stripos($key,"fmCheck_") !== false){ $sql = "INSERT INTO products_required VALUES (".$value.");"; $rs = mysql_query($sql); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1188934 Share on other sites More sharing options...
friedice Posted March 25, 2011 Author Share Posted March 25, 2011 hmm if i were to post this page using the form, how would i end up grabin all the checkboxes (checked and unchecked) from the previous page and then insert them accordinly into the db with this i can echo the last row for its return back to the page how can i post only the checked ones into the next page and then save them to the db? Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1192020 Share on other sites More sharing options...
friedice Posted March 25, 2011 Author Share Posted March 25, 2011 or is there any easier to achieve this goal without checkboxes? Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1192041 Share on other sites More sharing options...
aabid Posted March 25, 2011 Share Posted March 25, 2011 When you use multiple checkboxes then you must use array variable as a name of checkbox, for example:- <input type="checkbox" name="formDoor[]" value="A" />Acorn Building<br /> <input type="checkbox" name="formDoor[]" value="B" />Brown Hall<br /> <input type="checkbox" name="formDoor[]" value="C" />Carnegie Complex<br /> <input type="checkbox" name="formDoor[]" value="D" />Drake Commons<br /> <input type="checkbox" name="formDoor[]" value="E" />Elliot House Now the value $_POST[formDoor] is only set when a user checks any of the available checkboxes. And all the selected ones are stored as an array in variable $_POST[formDoor] Now all you have to do is use foreach and extract every value stored in $_POST[formdoor] Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1192043 Share on other sites More sharing options...
friedice Posted March 25, 2011 Author Share Posted March 25, 2011 hmm ok i was tryin to store them as an array but it wouldnt print anything could u give me an example of how the foreach loop would work to extract each value from the array? thx Quote Link to comment https://forums.phpfreaks.com/topic/230792-checkboxes-help/#findComment-1192044 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.