jigsawsoul Posted January 24, 2010 Share Posted January 24, 2010 Hi. I have a list of staff member's, http://stuweb.cms.gre.ac.uk/~hr728/_web/_admin/meeting/test.php Each one has a checkbox, when submitted i which to call up the staff_id of only the ones that was selected, but i don't have a clue where to start? any help please. <?php session_start(); include '../../_library/opendb.php'; include '../../_functions/login.php'; include '../../_functions/nav-admin.php'; $result = "SELECT * FROM web_staff LEFT JOIN web_login ON web_staff.login_id=web_login.login_id WHERE userlevel = '2' ORDER BY firstname ASC"; $result = mysql_query($result) or die( mysql_error() ); while($row = mysql_fetch_assoc($result)) { $meetings .= ' <form action="add3.php" method="post"> <div class="meeting png_bg"> <table> <tr> <td width="150px">'.$row['firstname'].' '.$row['lastname'].'</td> <td><input type="checkbox" name="'.$row['staff_id'].'" value="'.$row['staff_id'].'" unchecked></td> </tr> </table> </div> </form> '; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189574-how-do-i-use-checkboxes-with-php-help-please/ Share on other sites More sharing options...
oni-kun Posted January 24, 2010 Share Posted January 24, 2010 In your source, you should make each checkbox's 'name' attribute. name="foobar[]" And from in PHP, you can access it via $_POST['foobar'] Try var_dump'ing it to see what the layout looks like. Quote Link to comment https://forums.phpfreaks.com/topic/189574-how-do-i-use-checkboxes-with-php-help-please/#findComment-1000612 Share on other sites More sharing options...
jigsawsoul Posted January 24, 2010 Author Share Posted January 24, 2010 I'm really not getting this at all i have tried tutorials and asked for help a number of times but still no enjoy for me here, would anyone be so kind to change my current php code and post a work example. it mean so much thank you Quote Link to comment https://forums.phpfreaks.com/topic/189574-how-do-i-use-checkboxes-with-php-help-please/#findComment-1000615 Share on other sites More sharing options...
oni-kun Posted January 24, 2010 Share Posted January 24, 2010 I'm really not getting this at all i have tried tutorials and asked for help a number of times but still no enjoy for me here, would anyone be so kind to change my current php code and post a work example. it mean so much thank you You'll never get anywhere if you don't learn how to do it. Getting code means nothing. Try this example to see what happens: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="checkbox" value="foo" name="foobar[]"/> Foo<br/> <input type="checkbox" value="bar" name="foobar[]"/> Bar<br/> <input type="checkbox" value="baz" name="foobar[]"/> Baz<br/> <input type="submit" value="submit"/> </form> <?php if (isset($_POST['foobar'])) { echo '<pre>'; echo print_r($_POST['foobar']); } ?> Now you'll have three checkboxes. if you hit 'foo' and 'baz', You'll get this result when submitting: Array ( [0] => foo [1] => baz ) Simple, see? You can use a foreach loop to record the $_POST values within foobar[] or whatever array you choose, and in the loop do the query. Quote Link to comment https://forums.phpfreaks.com/topic/189574-how-do-i-use-checkboxes-with-php-help-please/#findComment-1000626 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.