checkbox

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
sahur
Forum Newbie
Posts: 1
Joined: Tue Jul 15, 2008 8:18 pm

checkbox

Post by sahur »

my codes like this:
$data=mysql_query("SELECT* FROM data");
while($a=mysql_fetch_array($data)){
$b=$a['name'];
echo '<input type="checkbox" name="check" value='.$b.">".$b."</br>";
}
output:
[] John
[] James
[] Nicholas

$d=$_POST['check'];
echo $d;
i use this code to display the names above but its only display only one name . what codes should i use to display all the names if i check all the names above?
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: checkbox

Post by EverLearning »

echo '<input type="checkbox" name="check[]" value='.$b.">".$b."</br>";

and since $_POST check will be an array, you won't be able to get the values with echo. You'll need somethig like

Code: Select all

 
$checked = isset($_POST['check']) ? $_POST['check'] : array();
foreach($checked as $value) {
    echo $value;
}
Post Reply