注意: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

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>";
          }
      }
?>

You have to check isset() not NULL

if(isset($_POST["ReqQty"]) && $_POST["ReqQty"]=="" )

This error happens because the field is not present on the request, so you dont have a ReqQty key on $_POST. To prevent that, you must check if the key is present, then validate it.

A nicer way to check would be:

if (!isset($_POST["ReqQty"]) || !$_POST["ReqQty"]) {
    // error
}

remove disabled; if you want you can use hidden. from your input field

A disabled input element is unusable and un-clickable. means you can not use them. They send no value further

You can use readonly tag if you want to as i am using in my answer. (suggested by @ghost.)

<td colspan="3"><input name="ReqQty" id="ReqQty" onkeypress="return numbersOnly(event)" onkeyup="ItmQty_Availability()" readonly>

Check this

<td colspan="3"><input name="ReqQty" id="ReqQty" onkeypress="return numbersOnly(event)" onkeyup="ItmQty_Availability()" <?php if($condition==TRUE){echo "disabled=disabled";}?>>