dqlk31541 2013-07-29 11:42
浏览 54
已采纳

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

I cannot get the $_POST['value'] after form submission.

I have used javascript to assign a value to an input field. code:

function updateValue(pid, value){
    // this gets called from the popup window and updates the field with a new value
    document.getElementById(pid).value = value;
}

The above function is called by a popup widow to assign a value to my input field: pid

Here is the form script:

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

In my test.php, I have done:

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);   
}

But I am getting the error: Undefined index: project_name

  • 写回答

4条回答 默认 最新

  • dongpuchao1680 2013-07-29 11:44
    关注

    Disabled inputs doesnt post. Use hidden input like this:

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答