MoonPoint Support Logo


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals

Advanced Search
Sun Mon Tue Wed Thu Fri Sat

Mon, Jul 03, 2017 10:03 pm

is_null versus empty in PHP

I have a PHP script that queries an SQLite database displaying the results on a web page. There are two fields, "EC Link" and "Configs Link" in the database that can contain URLs pointing to documentation on another server, but sometimes there is no URL in the database for those fields. If there is a URL, I want to display a clickable "EC" and "Configs" links. If there is no URL in either field, I want to simply display the text, but without it being clickable to indicate that there is no URL in the database table. I was using "is_null" for that purpose as shown below:

   if (is_null($row['EC Link'])) {
       echo "EC | ";
    else {
       echo "<a href=\"" . $row['EC Link'] . "\">EC</a> | ";
    if (is_null($row['Configs Link'])) {
       echo "Configs | ";
    else {
       echo "<a href=\"" . $row['Configs Link'] . "\">Configs</a> | ";

But I found that sometimes I was seeing clickable links even though there was no URL for the EC and/or Configs documentation for a particular record in the database. When I checked the records in the relevant table in the database, I found that the fields were blank, i.e., there was no data in them, but they weren't marked as null. So, to allow for the values being either null or blank, I used an empty, instead of is_null, test.

[ More Info ]

[/languages/php] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo