Jump to content

Check if Data Exists


datoshway

Recommended Posts

There are many ways of checking for data in a variable. The first two that come to mind are isset() and empty() which both return bool values, as expected. So you could do this:

<?php
if(isset($strFilename) && !empty($strFilename) { /* if it exists and is not empty */ ?>
     <img src="" ... />
<?php } else { ?>
     // filler content here
<?php }

 

There are other functions as well for checking data types. is_string(), for example, might be useful to you. You can see a list of similar ones at http://php.net/manual/en/ref.var.php.

Thanks for the reply.  That actually have me a syntax error.

 

Parse error: syntax error, unexpected '{' in /news.php on line 246

 

I don't think these forums are there to do your work for you, it exists purely as a form of help. Some of the developers here don't have time to test their code and purely submit concepts. That error is really easy to fix and if you can't fix that then I would suggest to download "php for dummies".

Change

) && !empty($strFilename) { 

-->

) && !empty($strFilename)) {

 

There was a missing bracket.

 

I don't think these forums are there to do your work for you, it exists purely as a form of help. Some of the developers here don't have time to test their code and purely submit concepts. That error is really easy to fix and if you can't fix that then I would suggest to download "php for dummies".

 

Are you daft?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.