I have 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" />
<title>Loughborough University | Students Union</title>
<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));
print_r($day);
?>
<form action="test.php" method="post">
Day:
<select name="day">
<?php foreach($day[0]++ as $key => $value) { ?>
<option value="<?php echo $key ?>" ><?php echo $value ?></option>
<?php }?>
</select>
<br>
Month:
<select name="month">
<?php foreach($month[0]++ as $key => $value) { ?>
<option value="<?php echo $key ?>" ><?php echo $value ?></option>
<?php }?>
</select>
<br>
Year:
<select name="year">
<?php foreach($year[0]++ as $key => $value) { ?>
<option value="<?php echo $key ?>" ><?php echo $value ?></option>
<?php }?>
</select>
<input type='submit' value='send' name='send' />
</form>
</body>
</html>
and 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" />
<title>Loughborough University | Students Union</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<?php
$day = $_POST["day"];
$month = $_POST["month"];
$year = $_POST["year"];
echo $day;
echo $month;
echo $year;
?>
Date Selected: <?php echo $_POST["day"];echo $_POST["month"];echo $_POST["year"]; ?>
</body>
</html>
However, say for example i choose, day 1, month 1, and year 2011 it comes out with 000. Why is this and what can i do to correct this?
Thanks for any ideas or suggestions.
In every option you have to use
$valueinstead of$key:Because you pass to inputs just keys, not values.
For example:
creates an array:
so if you select
2014:is equals to
And in your posted
test.phppage you will get3as a year.So simply change as I descriped on the beggining will solve your problem.