I have two pages. One with the select boxes on and the send button. When the user chooses their options from the select boxes and clicks send it takes them to the second page which outputs their choices.
date_change.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<?php
$day = array(range(1,31));
$month = array(range(1,12));
$year = array(range(2011,2020));
?>
<form action="test.php" method="post">
Day:
<select >
<?php foreach($day[0]++ as $key => $value) { ?>
<option value="<?php echo $key ?>" name="day"><?php echo $value ?></option>
<?php }?>
</select>
<br>
Month:
<select>
<?php foreach($month[0]++ as $key => $value) { ?>
<option value="<?php echo $key ?>" name="month"><?php echo $value ?></option>
<?php }?>
</select>
<br>
Year:
<select>
<?php foreach($year[0]++ as $key => $value) { ?>
<option value="<?php echo $key ?>" name="year"><?php echo $value ?></option>
<?php }?>
</select>
<input type='submit' value='send' name='send' />
</form>
</body>
</html>
Once the user makes their choices and clicks send it takes them to test.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
Date Selected: <?php echo $_POST["day"];echo $_POST["month"];echo $_POST["year"]; ?>
</body>
</html>
However, even though it goes to the test.php page it doesnt show what the user picked. Any help?
where am I going wrong?
You should add a
nameattribute to your<select>tags instead of your<option>tags.Also, you should change
<br>to<br />for XHTML valid code.Change you code to: