简体   繁体   中英

if column is null echoing in php getting wrong

I am creating a website in html using php and sql. there is a small section in which if the query didnt find the value, php will echo a message called vacant, but if the query finds the value in column, it will echo filled. the code is like below:

 <div style="padding-bottom: 10px;" class="col"> <?php $query=mysqli_query($con,"select * from king where title= 'SIMS'"); $sep=mysqli_fetch_array($query); $c1 = $sep['title']; if ($c1 == NULL){ $msg = "Vacant"; } else { $msg = "Filled"; } ?> <div class="counter col_fourth"> <h2 class="timer count-title count-number" data-to="300" data-speed="1500"></h2> <p class="count-text "> <?php echo $msg;?> </p> <p class="count-text ">title</p> </div> </div>

Now when I load the page, even if the value is present in the column, its still showing "vacant". Can anyone please help me with my code?

Note the ===

When use ==, as you did, PHP treats NULL, false, 0, the empty string, and empty arrays as equal

<?php
$query=mysqli_query($con,"select * from king where title= 'SIMS'");
$sep=mysqli_fetch_array($query);
$c1 = $sep['title'];

if ($c1 === NULL){    
    $msg = "Vacant";
}
else {
    $msg = "Filled";
}    
?>

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