\n";
// BTW, if this were a web app we'd likely be saving this data
// to a database rather than displaying on the screen. More on that
// later.
// checkboxes are "special" in that if the checkbox is checked the
// value is set to "on" and if the checkbox is not checked the value
// is not sent at all! This is a good place for the ternary operator:
$yesorno= isset($_POST['yesorno']) ? 'yes' : 'no';
echo "yesorno is: $yesorno
\n";
// If you want to access an array element in a variable-interpolated
// string the index is assume to be a constant. Notice the 's are
// not included ...
echo "color is: $_POST[color]
\n";
// Or use concatentation ...
// NOTE: if none of the radio buttons are checked then nothing is sent
// (as with checkboxes). Although we can't trust what comes from the
// client I have side-stepped the issue for this simple example, by
// having one of the radio buttons selected when the page loads which
// ensures one of them will be selected.
echo 'upordown is: ' . $_POST['upordown'] . "
\n";
// Instead of echoing the propmt and the
tag we can close the
// PHP section and then reopen it only for displaying the variable:
?>
Comments:
A (Self-Posting) Form ...