PHP empty($row['Column'])) seems to be reversed

I would like to put a few images next to each other in a (sort-of) edit.php file.

If the column is empty, I would like to add the option to upload another a file into it.

If the column is filled, I would like it to display what's in it (a path to an image).

The problem is this, if I execute this code it will do the opposite of what I'm expecting it to do.

the column is empty, yet it will execute the code after the else, meaning it thinks it's filled.

If feel like i'm just missing something but I can't find anything about this.

I've tried replacing (empty['COLUMN'])) with (!empty['COLUMN'])), (isset['COLUMN'])) and (!isset['COLUMN'])). Same results every time.

    $sql = "SELECT * FROM TABLE WHERE id = '$id'";
        if($res = mysqli_query($conn, $sql)){
    if(mysqli_num_rows($res) > 0){
      while($row = mysqli_fetch_array($res)){
        if(empty($row['COLUMN1'])) {
      echo '<input type="file" class="form-control-file"  name="COLUMN1">'; 
} else {
echo '<a href="' . $row['COLUMN1'] . '"><img src="' . $row['COLUMN1'] . '"></a>';

I expected the PHP to execute the first piece of code (after the initial if statement) if the column is empty. Yet it executes the second.

1 answer

  • answered 2019-06-12 14:29 Michael Kok

    Solved! Somehow in my handler.php a space was added, even if there was nothing to put unto the database. Also explains why I couldn't see what was coming out of echo $row['COLUMN1']. Woohoo!