简体   繁体   English

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

[英]how to get listbox value in another php page

i think i am doing some mistake in my code. 我认为我在代码中犯了一些错误。 can someone please correct me. 有人可以纠正我吗? how to get the list box values in another page. 如何在另一个页面中获取列表框值。

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 contains below code. fetch_test.php包含以下代码。

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

You are using the name as an Array . 您正在使用该名称作为Array

Fixed code: 固定代码:

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>";

You stored it in an array, so call it in an array also. 您将其存储在数组中,因此也请在数组中调用它。

<?php

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

?>

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

Unless there are more than one name='fromdate' or name='frommonth' , you don't need the [] . 除非存在多个name='fromdate'name='frommonth' ,否则不需要[]

Just try normal: 只需尝试正常:

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

Make sure you put ' around the name attribute! 确保在name属性周围加上'

Then use: 然后使用:

$_POST['fromdate'];

At the moment you're putting it into an array, so if you want to keep it the way it is, use: 目前,您将其放入数组中,因此,如果要保持其原样,请使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM