Andrew R Posted October 10, 2006 Share Posted October 10, 2006 HiI am having trouble writing a script that will select multiple flight ids (from a checkbox) and process them into another page via the $_POST function So for example I select flight id (RFS1869 and RFS5697 from the checkbox) and it will display information about these two results in another page.Can anybody point me in to any tutorials or anything that will help with learn how to do this.Cheers Quote Link to comment https://forums.phpfreaks.com/topic/23578-selecting-multiple-checkboxes/ Share on other sites More sharing options...
.josh Posted October 10, 2006 Share Posted October 10, 2006 in your form:[code]<form action='target.php' method='post'> <input type = 'checkbox' name = 'somevar[]' value = 'rfs1869'> rfs1869 <br> <input type = 'checkbox' name = 'somevar[]' value = 'rfs5697'> rfs5697 <br> <input type = 'submit' value='submit'></form>[/code]target.php[code]$somevar = $_POST['somevar'];// exampleforeach ($somevar as $val) { echo "$val <br>"; // echo out each element in $somevar array}//another exampleecho $somevar[0]; //echos first checkbox that was checkedecho $somevar[1]; //echos 2nd checkbox that was checked[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23578-selecting-multiple-checkboxes/#findComment-107048 Share on other sites More sharing options...
Andrew R Posted October 10, 2006 Author Share Posted October 10, 2006 Cheers for that, although the only problem being the values for flight_id are being pulled out from the database and then displayed in a table. [code]<?php echo $row_flights['flight_id']; ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23578-selecting-multiple-checkboxes/#findComment-107051 Share on other sites More sharing options...
Daniel0 Posted October 10, 2006 Share Posted October 10, 2006 If you want to get the values for the checkboxes from the database, then you can do it like this: [code]while($row = mysql_fetch_assoc($query_result){ echo "\t<label><input type='checkbox' name='flight_ids[]' value='{$row['value']}' /> {$row['user_readable_name']}</label>\n";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23578-selecting-multiple-checkboxes/#findComment-107053 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.