提交表单后我无法获取$_POST['value']
。
我使用 javascript 为输入字段赋值。 代码:
function updateValue(pid, value){
// this gets called from the popup window and updates the field with a new value
document.getElementById(pid).value = value;
}
上面的函数被弹出窗口调用,为我的输入字段赋值:pid
这是表单
脚本:
<form action="test.php" method="post">
<input type="text" name="project_name" id="pid" disabled="disabled" />
<input type="submit" id="search" name="search" value="Search" />
</form>
在我的 test.php 中,我做了:
include 'functions.php'; //Has the connection script
if (isset($_POST['search'])){
echo $project_id = $_POST['project_name'];
$sql = mysql_query("SELECT * from item
where category like '$project_id %'
");
echo $num = mysql_num_rows($sql);
}
但我收到错误:Undefined index: project_name
最佳答案
禁用的输入不会发布。像这样使用隐藏
输入:
<form action="test.php" method="post">
<input type="text" name="project" disabled="disabled" />
<input type="hidden" name="project_name" id="pid" />
<input type="submit" id="search" name="search" value="Search" />
</form>
关于php - 无法使用 PHP $_POST 数组检索输入字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17923097/