Jump to content

How Do I Use CHECKBOXES with PHP?? HELP PLEASE!!!!


jigsawsoul

Recommended Posts

O0

 

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>
	';		
 }
?>

 

 

 

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

:hail_freaks:

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.