Getting checkbox values in POST (PHP)

<html>

<head>

<title>checkbox help</title>

</head>

<?

 

if (isset($HTTP_POST_VARS)) {

 

$fruit = $HTTP_POST_VARS["fruit"];

 

echo("Fruits chosen: " . count($fruit) . "<br><br>");

 

if (count($fruit)>0) {

echo("You chose the following fruits:<br>");

}

 

for ($i=0; $i<count($fruit); $i++) {

echo( ($i+1) . ") " . $fruit[$i] . "<br>");

}

}

?>

<body bgcolor="#ffffff">

 

<form method="post">

Choose a fruit:<br><br>

<input type="checkbox" name="fruit[]" value="apples">apples <br>

<input type="checkbox" name="fruit[]" value="oranges">oranges <br>

<input type="checkbox" name="fruit[]" value="peaches">peaches <br>

<input type="checkbox" name="fruit[]" value="mangos">mangos<br>

<input type="submit">

</form>

 

</body>

<html>

0 comments:

Post a Comment

 
Copyright © SERVER CODES