无法使用 PHP 从一个页面获取信息到另一页面
我有两页。一个带有选择框和发送按钮的。当用户从选择框中选择他们的选项并单击“发送”时,会将他们带到输出他们的选择的第二页。
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>
一旦用户做出选择并单击“发送”,就会将其带到 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>
但是,即使它转到 test.php 页面,它也不会显示用户选择的内容。有什么帮助吗?
我哪里出错了?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该将
name
属性添加到另外,您应该将
更改为
以获得 XHTML 有效代码。将您的代码更改为:
You should add a
name
attribute to your<select>
tags instead of your<option>
tags.Also, you should change
<br>
to<br />
for XHTML valid code.Change you code to:
您的
It is your
<select>
elements which need the month/day/year name attributes, not their child options:您的
name
属性应位于select
元素上,而不是其option
上。Your
name
attributes should be on theselect
elements, not theiroption
s.您需要在
You need to specify the
name
attribute on the<select>
element, not the<option>
, like this:name
属性出现在select
上,而不是每个单独的option
上。The
name
attribute goes on theselect
, not each individualoption
.