0

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.

  • I think this is an [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). You don't check if status is empty, you check if query returned something. I think you've disabled error reporting and don't really see that acessing `$ro['status']` fails when there are no results. – FirstOne Nov 01 '17 at 14:20
  • The result will be empty right if there is no record with that specified name. Then , can i directly access that if $res == "" – Naga Bhavani Nov 01 '17 at 14:33
  • I don't know what `$res` is, but there are better ways of checking if the query found any results than using `== ""`. Such as [Best way to check if MySQL results returned in PHP?](https://stackoverflow.com/questions/4286586/best-way-to-check-if-mysql-results-returned-in-php). **Warning: the linked question uses deprecated API, adapt it accordingly.** – FirstOne Nov 01 '17 at 14:34

1 Answers1

0

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"); 
}
hungl
  • 71
  • 7