简体   繁体   中英

How to [erform condition when null is retrived from the database using php?

I am retrieving the details from the database if the condition is satisfied. But when the condition is not satisfied, empty result is retrived. So how to have a condition if status is empty

My code

php

           $sq=mysqli_query($link,$query);
           $ro=mysqli_fetch_array($sq);
           $status=$ro['status'];

       if($status==1){
            header("location: paymentPage.php");

       }
       else if($status==0){
               header("location:login.php");
           }
       else if($status == '\0')
       {
          header("location:SignUp.php"); 
       }

But i am not able to redirect to signup page if the status is empty. Can anyone help me solve this problem.Is status=='\\0' is correct to go for signup page.

Thank You in advance.

If your column status has integer type in DB then it can't have value '\\0' because '\\0' is a string. Maybe you should use is_null function? For example:

else if(is_null($status))
{
    header("location:SignUp.php"); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM