sanjay
sanjay

Reputation: 31

empty field or blank field or null field is not shown in php code

Below is my code, In employee table there are some records whose pfuidno is null but it is not showing on server run where is my mistake

$sql1="select a.code,a.empname,a.pfuidno from emplmast a ";1
$get1=mysqli_query($conn,$sql1) or die(mysqli_error());
$m_no = mysqli_num_rows($get1);
if ($m_no!=0)
{
    while($row1 = mysqli_fetch_array($get1))
    {
        if ($row1['pfuidno']=='' OR empty($row1['pfuidno']))
        {
          $m_errmsg='UAN is Blank for Employee Code '.$row1['code'].' Name '.$row1['empname'];
          echo "<script language='javascript' type='text/javascript'>alert('$m_errmsg')</script>";
        }
    }
}

Upvotes: 1

Views: 88

Answers (1)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72289

1.remove 1 beside query code line.

2.Use _assoc() as you specified column-names in query.(Not compulsion, but will give you a lighter associative array)

3.OR need to be ||

4.Checking for NULL need to be added

Code need to be:-

$sql1="select a.code,a.empname,a.pfuidno from emplmast a "; // remove 1
$get1=mysqli_query($conn,$sql1) or die(mysqli_error());
$m_no = mysqli_num_rows($get1);
if ($m_no > 0){
    while($row1 = mysqli_fetch_assoc($get1)){ // use _assoc
        if ($row1['pfuidno']=='' || empty($row1['pfuidno']) || $row1['pfuidno'] === NULL){ //check for NULL
            $m_errmsg='UAN is Blank for Employee Code '.$row1['code'].' Name '.$row1['empname'];
            echo "<script language='javascript' type='text/javascript'>alert('$m_errmsg')</script>";
        }
    }
}

Upvotes: 2

Related Questions