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?
checkbox
Moderator: General Moderators
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: checkbox
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
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;
}