Getting value frm checkbox array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Getting value frm checkbox array

Post by winsonlee »

Code: Select all

foreach ( $body1 as $value ) {
	echo '<tr>';
	echo	'<td class="pformleft" width="53%">';
	echo $value;
	echo	'</td>';
	echo	'<td class="pformright" valign="top" width="33%" colspan="2" align="center">';
	echo	'<input type="checkbox" name="delete[]" value="index'.$counter.'">';
	echo	'</td>';
	echo '</tr>';
		$counter++;


		}
after submitting the form, how can i get the value for the checkbox that are submitted ??
ruchit
Forum Commoner
Posts: 53
Joined: Mon Sep 26, 2005 6:03 am

Post by ruchit »

use $_POST['delete'] to get values posted. To print the values, you can use

Code: Select all

<?php
print_r $_POST['delete']; 
?>
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Post by winsonlee »

how can i print value by value ??

like if checkbox 1 is true then echo checkbox 1 value
if checkbox 2 is true then echo checkbox 2 value
ruchit
Forum Commoner
Posts: 53
Joined: Mon Sep 26, 2005 6:03 am

Post by ruchit »

it would only show the selected values... so you can use

Code: Select all

foreach( $_POST['delete'] as $val )
    echo $val."<br> \n";
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Winsonlee when posting PHP code on the forums please use PHP tags.

About your question: Exactly like you specified.
I'm not certain, but you could use isset(), since cheboxes that are not checked are removed.
Post Reply