如何在另一个php页面中获取列表框值

时间:2014-03-14 09:30:52

标签: php post listbox webpage

我想我的代码中有些错误。请有人请指正。如何在另一页中获取列表框值。

print "<form method=\"post\" action=\"fetch_test.php\">";
print "Report From: ";
print "<select name=fromdate[]>";
print "<option selected=\"selected\">Date</option>";
print "<option value=01>01</option>";
print "<option value=02>02</option>";
print "<option value=03>03</option>";
print "</select>";

print "<select name=frommonth[]>";
print "<option selected=\"selected\">Month</option>";
print "<option value=jan>Jan</option>";
print "<option value=feb>Feb</option>";
print "<option value=mar>Mar</option>";
print "</select>";

print "<br><br>";
print "<input type=submit>";
print "</form>";

fetch_test.php包含以下代码。

<?php
print $_POST['fromdate'];
print $_POST['frommonth'];
?>

4 个答案:

答案 0 :(得分:1)

您使用的名称为Array

固定代码:

print "<form method=\"post\" action=\"fetch_test.php\">";
print "Report From: ";
print "<select name=fromdate>";
print "<option selected=\"selected\">Date</option>";
print "<option value=01>01</option>";
print "<option value=02>02</option>";
print "<option value=03>03</option>";
print "</select>";

print "<select name=frommonth>";
print "<option selected=\"selected\">Month</option>";
print "<option value=jan>Jan</option>";
print "<option value=feb>Feb</option>";
print "<option value=mar>Mar</option>";
print "</select>";

print "<br><br>";
print "<input type=submit>";
print "</form>";

答案 1 :(得分:0)

您将其存储在数组中,因此也可以在数组中调用它。

<?php

print $_POST['fromdate'][$yournumbervalue];
print $_POST['frommonth'][$yournumbervalue];

?>

答案 2 :(得分:0)

尝试引用您的select标记名称,您希望<select name="fromdate[]">获取数组,并且希望使用<select from="fromdate">获取单个值。

答案 3 :(得分:0)

除非有多个name='fromdate'name='frommonth',否则您不需要[]

试试正常:

print "<select name='fromdate'>";

确保在名称属性周围添加'

然后使用:

$_POST['fromdate'];

目前你将它放入一个数组中,所以如果你想保持原样,请使用:

foreach ($fromdate as $date){
  echo $date;
}