PHP Example from Prof Stone
Here is the example code from Prof Stone, who guest-lectured February 26 and 28. I’ve made some slight modifications to the code.
form_ex.php
<!DOCTYPE html>
<html>
<head>
<title>Form Example</title>
</head>
<body>
<form method="post" action="form_ex.php">
<h2>Day</h2>
<?php
$current_day = 31;
while ($current_day>0) {
echo "<input type='radio' name='day' value='$current_day'>$current_day ";
$current_day--;
}
?>
<h2>Month</h2>
<?php
echo "<select name='month'>";
for ($index=1;$index<13;$index++) {
echo "<option value='$index'>$index</option>";
}
echo "</select>";
?>
<h2>Year</h2>
<?php
echo "<select name='year'>";
for ($index=1950;$index<2025;$index++) {
echo "<option value='$index'>$index</option>";
}
echo "</select>";
?>
<input type="submit" name="submit" value="Search" /><br />
</form>
<?php
// err_reporting(E_ALL);
// ini_set('display_errors',1);
$year_value = $_POST['year'];
if( isset($year_value)) {
echo "your year value exists! it is $year_value";
} else {
echo "no year value ";
}
echo "<br />";
$month_value = $_POST['month'];
if (isset ($month_value)) {
echo "your month value exists! it is $month_value";
} else {
echo "no month value set";
}
echo "<br />";
$day_value = $_POST['day'];
if (isset ($day_value)) {
echo "your day value exists! it is $day_value";
} else {
echo "no day value set";
}
echo "<br />";
// THIS IS NOT THE SOLUTION, JUST TO DEBUG
echo $year_value+$month_value+$day_value;
?>
</body>
</html>