php - 无法使用 PHP $_POST 数组检索输入字段值

标签 php javascript dom

提交表单后我无法获取$_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/

相关文章:

php - 使用 NGINX : "no port in upstream php" error 配置管理员

javascript - 将 D3 日历 View 示例调整为垂直,日期从左到右排序,然后从上到下排序?

javascript - 如何限制 jQuery 和 javascript 中选择标签内的所选选项标签的数量?

javascript - 模拟用户点击让一个元素出现在 DOM 中

PhpStorm MySQL Connector/J 更新到 5.1.40 后停止工作

php - MySql 获取不同域的数量

javascript - 是否可以将 CSS 应用于字符的一半?

jQuery 选择器 : Grabbing a section of children that are of a given tag

javascript - document.head, document.body 附加脚本

php - 如何使用 php 在弹出窗口中显示服务器端错误消息