Something that helps a lot is the Return Values section of the PHP Manual, so we know how to evaluate the results of the functions.
In the case of mysqli_query , which is the function you're using, The Manual says the following in that section :
Returns FALSE in case of error. If a query of type SELECT ,
SHOW , DESCRIBE or EXPLAIN is successful, mysqli_query() will return
a mysqli_result object. For other successful consultations
mysqli_query() will return TRUE .
So when you use mysqli_query you have three possibilities of result:
-
FALSE ,
- an object
mysqli_result o,
-
TRUE .
That means that here:
$sql =mysqli_query ($mysqli, "SELECT hour_out FROM registro_lista WHERE num_c="316115377");
the heat of $sql will never be NULL even in case the query fails and the variable $sql acquires the value FALSE , since FALSE is not equal to NULL .
If, as you say, what you want to evaluate is the value of the column hour_out that the query brings you, then you must recover that value by reading the object that returns mysqli_query in case of success.
There are several methods to read the objects mysqli_result , one of the most used is mysqli_fetch_array which returns the value in an associative array in which each key is the name of each column of SELECT :
$sql =mysqli_query ($mysqli, "SELECT hour_out FROM registro_lista WHERE num_c='316115377'");
$row = mysqli_fetch_array($sql, MYSQLI_ASSOC);
$hour = $row["hour_out"];
And then you can compare by:
if (is_null($hour)) {
}
else{
}
Or simply by:
if ($hour) {
}
else{
}
Or using a ternary operator:
$resultado = ($hour) ? "No es nulo" : "Es nulo";
echo $resultado;
NOTE:
Attention to your query. I had a syntax error. I've put it like this:
"SELECT hour_out FROM registro_lista WHERE num_c='316115377'" but
if the column num_c is of a numeric type, it is better that you remove the
single quotes that surround the value, putting it like this: "SELECT
hour_out FROM registro_lista WHERE num_c=316115377"