Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

form field is blank when input value retreived from database is 0

Tags:

html

php

I have the following html-php input field on a form page:

<input type="text" id="subnet" name="subnet" class="inputText70px" maxlength="3" value=
      <?php
        if (!empty($eqptCheck['subnet'])){
          echo '"'.$ipAddressArr['subnet'].'">.';
        }else{
          echo '"">.';
        }
      ?>

Whenever I have any value other than 0 for the subnet it is displays properly in the page's input field. But when the subnet value is 0 the page's field is just empty. I assume my php must be the problem. Can anyone see what the issue with my php is that causes the issue?

like image 252
ahchrist Avatar asked Apr 17 '17 13:04

ahchrist


1 Answers

I think empty is true if for value == 0. So when your subnet value is 0, then the !empty condition is false and moves along to else that renders an empty "" value for the intput field.

If you instead use !is_null in place of !empty I think that should resolve your issue.

<input type="text" id="subnet" name="subnet" class="inputText70px" maxlength="3" value=
  <?php
    if (!is_null($eqptCheck['subnet'])){
      echo '"'.$ipAddressArr['subnet'].'">.';
    }else{
      echo '"">.';
    }
  ?>
like image 188
digiscripter Avatar answered Oct 27 '22 00:10

digiscripter