dongqiao1158 2014-10-31 04:26
浏览 20
已采纳

注意:php中的未定义索引(验证)

I want to validate my form and i got this error

Notice: Undefined index: ReqQty in C:\project\userequisition.php on line 180

This is my code :

    <td><label for="ReqQty">Quantity </label></td>
    <td colspan="3"><input name="ReqQty" id="ReqQty" onkeypress="return numbersOnly(event)" onkeyup="ItmQty_Availability()" disabled="disabled">

<?php
          $strReqQty = "";
          if(!empty($_POST)){
              if($_POST["ReqQty"]==NULL){ //ERROR here
                  echo "<font color=red>Enter the Quantity</font>";
              }else{
                  $strReqQty = $_POST["ReqQty"];
              }
          }
?>

I got the error only for this input type while everything works fine on others

  • 写回答

4条回答 默认 最新

  • doqau82086 2014-10-31 05:08
    关注

    use isset to check if key in $_POST exists

    <?php
          $strReqQty = "";
          if(!empty($_POST)){
              if(isset($_POST["ReqQty"])){
                  $strReqQty = $_POST["ReqQty"];
              }else{
                   echo "<font color=red>Enter the Quantity</font>";
              }
          }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题