用户点击提交时处理值

时间:2014-05-01 15:41:01

标签: php sql oracle

我有一个关于在页面内传递值以将其处理到数据库的问题。所以我有这个代码,当用户按下显示时,会显示一个从数据库中提取的表,用户应按ok或拒绝更新数据库。我的问题是当我按OK时,显示错误,

注意:未定义的索引:第43行的C:\ xampp \ htdocs \ WeltesInformationCenter \ Component_approval \ show_requested_component.php中的操作

我不知道错误在哪里,所以任何帮助都会非常感激

if ($_POST['action'] == 'show'){

  $requestCompParse = oci_parse($conn, $requestCompSql);
  oci_execute($requestCompParse);

  while($row = oci_fetch_assoc($requestCompParse)){

    echo "<form action='$_SERVER[PHP_SELF]' method='post'>";
    echo "<div class='table-responsive'>";
    echo "<table class='table table-bordered'>";
    echo '<table cellspacing = "0"';
    echo '<thead>';
    echo '<tr>
      <th>PROJECT</th>
      <th>BASEPLATE</th>
      <th>THICKNESS</th>
      <th>QTY REQUESTED</th>
      <th>QTY REQUIRED</th>
      <th>QTY CNCED</th>
      <th>REQUESTER</th>   
      <th>REQ. DATE</th>
      <th align="center">ACTION</th>  
      </tr>
      </thead>';

    echo "<tbody>";
    echo "<tr class='warning'><td>$row[PROJECT_NAME]</td>";
    echo "<td>$row[BASE_PLATE]</td>";
    echo "<td>$row[THICKNESS]</td>";
    echo "<td>$row[QTY_REQUESTED]</td>";
    echo "<td>$row[QTY_REQUIRED]</td>";
    echo "<td>$row[QTY_CNCED]</td>";
    echo "<td>$row[REQUESTER]</td>";
    echo "<td>$row[REQUEST_DATE]</td>";
    echo "<td><input type='submit' value='OK' class='btn btn-success'>
    <input type='button' value='REJECT' class='btn btn-danger'></td>";

    echo "</tr>";
    echo "</tbody>";
    echo "<table cellspacing = '0'";
    echo "</form>";

    if (isset($_POST['submit'])){

      $qtyToBeInserted = ($row[QTY_REQUESTED] + $row[QTY_CNCED]);

      $approvedSql = "UPDATE COMPONENT_CUTTING SET QTY_CNCED = :qtyToBeInserted WHERE BASE_PLATE = :basePlate 
                      AND THICKNESS = :thick AND PROJECT_NAME = :projName";

      $approvedSqlParse = oci_parse($conn, $approvedSql);

      oci_bind_by_name($approvedSqlParse, "qtyToBeInserted", $qtyToBeInserted);
      oci_bind_by_name($approvedSqlParse, "basePlate", $row[BASE_PLATE]);
      oci_bind_by_name($approvedSqlParse, "thick", $row[THICKNESS]);
      oci_bind_by_name($approvedSqlParse, "projName", $row[PROJECT_NAME]);

      $approvedSqlRes = oci_execute($approvedSqlParse);

        if ($approvedSqlRes){
          oci_commit($conn);
        } else {
          oci_rollback($conn);
        }
      }  

    echo "</div>";

1 个答案:

答案 0 :(得分:2)

这是因为您生成的表单没有名为action的元素。当你去检查数组元素的值时,如果数组中不存在该元素,而不是PHP对自己说“嗯,它不在这里,所以我称之为FALSE”(或者那些沿着这些方向的东西) ,它说“呸!它不在这里!我做的WTF?!?!” :)所以你必须先握住PHP的手并首先检查元素的存在,然后,如果它在那里,检查值。

您应该将if语句更改为此。

if (isset($_POST['action']) && $_POST['action'] == 'show'){

修改

根据您的评论,我会稍微修改您的代码流并执行类似的操作......

if (isset($_POST['action']) && $_POST['action'] == 'show'){

  $requestCompParse = oci_parse($conn, $requestCompSql);
  oci_execute($requestCompParse);

  while($row = oci_fetch_assoc($requestCompParse)){

    echo "<form action='$_SERVER[PHP_SELF]' method='post'>";
    echo "<div class='table-responsive'>";
    echo "<table class='table table-bordered'>";
    echo '<thead>';
    echo '<tr>
      <th>PROJECT</th>
      <th>BASEPLATE</th>
      <th>THICKNESS</th>
      <th>QTY REQUESTED</th>
      <th>QTY REQUIRED</th>
      <th>QTY CNCED</th>
      <th>REQUESTER</th>   
      <th>REQ. DATE</th>
      <th align="center">ACTION</th>  
      </tr>
      </thead>';

    echo "<tbody>";
    echo "<tr class='warning'><td>$row[PROJECT_NAME]<input type='hidden' name='PROJECT_NAME' value='$row[PROJECT_NAME]'/></td>";
    echo "<td>$row[BASE_PLATE]<input type='hidden' name='BASE_PLATE' value='$row[BASE_PLATE]'/></td>";
    echo "<td>$row[THICKNESS]<input type='hidden' name='THICKNESS' value='$row[THICKNESS]'/></td>";
    echo "<td>$row[QTY_REQUESTED]<input type='hidden' name='QTY_REQUESTED' value='$row[QTY_REQUESTED]'/></td>";
    echo "<td>$row[QTY_REQUIRED]<input type='hidden' name='QTY_REQUIRED' value='$row[QTY_REQUIRED]'/></td>";
    echo "<td>$row[QTY_CNCED]<input type='hidden' name='QTY_CNCED' value='$row[QTY_CNCED]'/></td>";
    echo "<td>$row[REQUESTER]<input type='hidden' name='REQUESTER' value='$row[REQUESTER]'/></td>";
    echo "<td>$row[REQUEST_DATE]<input type='hidden' name='REQUEST_DATE' value='$row[REQUEST_DATE]'/></td>";
    echo "<td><input type='submit' value='OK' class='btn btn-success'>
    <input type='button' value='REJECT' class='btn btn-danger'></td>";

    echo "</tr>";
    echo "</tbody>";
    echo "</table>";
    echo "</form>";
    echo "</div>";
  }// ends the WHILE loop
}// ends the IF
else if (isset($_POST['submit'])){

    $qtyToBeInserted = ($_POST[QTY_REQUESTED] + $_POST[QTY_CNCED]);

    $approvedSql = "UPDATE COMPONENT_CUTTING SET QTY_CNCED = :qtyToBeInserted WHERE BASE_PLATE = :basePlate 
                      AND THICKNESS = :thick AND PROJECT_NAME = :projName";

    $approvedSqlParse = oci_parse($conn, $approvedSql);

    oci_bind_by_name($approvedSqlParse, "qtyToBeInserted", $qtyToBeInserted);
    oci_bind_by_name($approvedSqlParse, "basePlate", $_POST[BASE_PLATE]);
    oci_bind_by_name($approvedSqlParse, "thick", $_POST[THICKNESS]);
    oci_bind_by_name($approvedSqlParse, "projName", $_POST[PROJECT_NAME]);

    $approvedSqlRes = oci_execute($approvedSqlParse);

    if ($approvedSqlRes){
        oci_commit($conn);
        echo "SUCCESS!!" // or whatever you want to display on successful save
    } else {
        oci_rollback($conn);
        echo "ERROR!!" // or whatever you want to display when there was an error
    }
}// ends ELSE IF