I'm trying to print multiple selections of checkboxes. I would like for when a user checks a checkbox or multiple, that the form will show what the user selects. For example, if a user checks shoe1, shoe2, shoe3 it will print shoe1, shoe2, shoe3. If a user checks shoe1, shoe2 it will print shoe1 and shoe2. If a user checks shoe1 it will only print shoe1 and so on..
I have tried using if, elseif, else statements but I think my logic is messed up because they don't work every time I try running it.
Here is my code:
What clothing brands do you like?<br />Nike<input type="checkbox" name="nike" value="nike"
<?php
if ($_POST['nike'] == 'nike') {
echo "checked";
}
?>
/>
Adidas<input type="checkbox" name="adidas" value="adidas"
<?php
if ($_POST['adidas'] == 'adidas') {
echo "checked";
}
?>
/>
Polo Ralph Lauren<input type="checkbox" name="rl" value="rl"
<?php
if ($_POST['rl'] == 'rl') {
echo "checked";
}
?>
/>
Vans<input type="checkbox" name="vans" value="vans"
<?php
if ($_POST['vans'] == 'vans') {
echo "checked";
}
?>
/>
<br />
Calvin Klein<input type="checkbox" name="ck" value="ck"
<?php
if ($_POST['ck'] == 'ck') {
echo "checked";
}
?>
/>
Kenneth Cole<input type="checkbox" name="kc" value="kc"
<?php
if ($_POST['kc'] == 'kc') {
echo "checked";
}
?>
/>
Rock Brand 1<input type="checkbox" name="rband1" value="rband1"
<?php
if ($_POST['rband1'] == 'rband1') {
echo "checked";
}
?>
/>
Rock Brand 2<input type="checkbox" name="rband2" value="rband2"
<?php
if ($_POST['rband2'] == 'rband2') {
echo "checked";
}
?>
/>
I would like the user to see what they've checked so it is user friendly. I'm also not too sure if you put all of these variables in one class that it will be easier like that.
Aucun commentaire:
Enregistrer un commentaire