Learning PHP and MySQL

Figure 10-09 Selecting Italian and Chinese

<html>
<
head>
   <
title>Using  Default  Checkbox  Values</title>
</
head>
<
body>
<?
php
$food
=$_GET[food];
$self=$_SERVER['PHP_SELF'];
if  (!empty(
$food))
{
   
echo  "The  foods  selected  are:<br  />";
   foreach(
$_GET[food]  as  $foodstuf)
   
{

      }
   }
else
{
   
echo  ("<form  action=\"$self\"  ");
   echo  (
'method="get">
   <fieldset>
     <label>Italian  <input  type="checkbox"  name="food[]"  value="Italian"  /></label>
     <label>Mexican  <input  type="checkbox"  name="food[]"  value="Mexican"  /></label>     
     <label>Chinese  <input  type="checkbox"  name="food[]"  value="Chinese"
checked="checked"  /></label>
     </fieldset>
       <input  type="submit"  value="Go!"  >
             '
);
}
?>
</body>
</html>

This code displays the graphic Figure 10-09 in the book.

Posted by on 08/18 at 11:03 AM

Next entry: Example 10-06 Checking input from a radio button or a single select

Previous entry: Example 10-05 A form with checkboxes using the same name to store multiple values

<< Back to main