PHP 代码没有从 POST 提交数据

标签 php html

在我尝试添加这条语句之前它一直有效

<?php echo "<input type=\"hidden\" name=\"hidden1\" value=\"$id\">" ?>

我之前能够从我的表单中获取索引号,但是当我添加该行时,字段中似乎没有加载任何内容。

这是完整的表格:

  <form name="approveform" method="POST" action="">
    <?php echo "<input type=\"hidden\" name=\"hidden1\" value=\"$id\">" ?>
    Index Number*: <input type="text" name="IndexNum">&nbsp;
    <input type="submit" value="Approve" action="">
  </form>

时间不早了,我可能需要去 sleep 了,但我太接近了!!!这是处理 POST 的完整代码。

if($user_data['permissions'] >= 1)
{
    // If users permission is 1 or 2 they get a field for inputting the index # and a button to change the approve field from 0 to 1 may need to make a new field to record who approved it....

    //Determine if the order is already approved.  If not approved show index field and allow user to approve it with index number
    if($data2[0]['Approved'] == 1)
    {
        echo " <font color=\"green\"> Approved";
    }
    if($data2[0]['Approved'] == 0)
    {
        echo " Not Approved.  Supply an index number and click approve to authorize this order to be completed.";
        if (empty ($_POST) === false) 
        {
               $required_fields = array('IndexNum');
           foreach ($_POST as $key=>$value)
           {
             if (empty($value) && in_array($key, $required_fields) === true)
             {
            $errors[] = 'Fields marked with an asterisk are required';
            break 1;
              }
           }
           if (isset($_POST['success']) === true && empty($_POST['success']) === true)
           {
               echo 'Index has been updated and Order is now set to Approved';
           }
           else
           {
            if (empty($errors) === true)
             {
                    $indexnum=$_POST['IndexNum'];
                $approvedby=$user_data['lname'];
                $vendorid1= $_POST['hidden1'];
                echo $indexnum;
                echo $approvedby;
                echo $vendorid1;
                    //update_approved($indexnum, $approvedby, $vendorid1);
                //header('Location: index.php');
                //exit();
            }
            else if(empty($errors) === false)
            {
                echo output_errors($errors);
            }
        }
     }
     ?>         
    <form name="approveform" method="POST" action="">
      <?php echo "<input type=\"hidden\" name=\"hidden1\" value=\"$id\">" ?>
      Index Number*: <input type="text" name="IndexNum">&nbsp;
      <input type="submit" value="Approve" action="">
    </form>

    <?php } 

}

感谢大家对此的关注。我从之前的 POST 中获得了 $id 值。我在代码的其他地方使用它没有问题。

非常感谢大家!

最佳答案

试试看

<input type="hidden" name="hidden1" value="<?php echo $id;?>">

也试试看

<?php echo '<input type="hidden" name="hidden1" value=".$id.">' ?>

关于PHP 代码没有从 POST 提交数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19020735/

相关文章:

javascript - Material Design Lite JS 不适用于动态加载的 html 文件

php - 用于连接多个表的 Laravel ORM

php - 将 Zval 转换为 char*

php - 完美的 PHP/MySQL 登录脚本无法正常工作

html - 右侧的额外空间

javascript - JS不识别cordova的插件

php - 需要根目录下的文件

php - 删除与 Laravel 5 的一对多关系

javascript - 我的数组的第一个元素没有显示

html - 尽管最大高度设置为 100%,但图像变得比父级大