PHP and checkboxes, printing the checkboxes selected in the form. How?

Gian

New member
I have a form and it contains checkboxes, when i click the submit button, the next php page should display the checkboxes that i selected. How do I do this? please help
 
Page1.php

<form target="page2.php" action="post">
<input type="checkbox" name="option1" value="Milk"> Milk<br>
<input type="checkbox" name="option2" value="Butter" checked> Butter<br>
<input type="submit" value="press me" />
</form>

--------------------------------------

page2.php

<?php
$milk = $_POST['option1'];
$butter = $_POST['option2'];

if($milk == 'checked')
{
echo "Milk<br />";
}
if($butter == 'checked')
{
echo "Butter<br />";
}
?>

that should work :)
 
Page1.php

<form target="page2.php" action="post">
<input type="checkbox" name="option1" value="Milk"> Milk<br>
<input type="checkbox" name="option2" value="Butter" checked> Butter<br>
<input type="submit" value="press me" />
</form>

--------------------------------------

page2.php

<?php
$milk = $_POST['option1'];
$butter = $_POST['option2'];

if($milk == 'checked')
{
echo "Milk<br />";
}
if($butter == 'checked')
{
echo "Butter<br />";
}
?>

that should work :)
 
Back
Top