Jump to content

Check if Data Exists


datoshway

Recommended Posts

I am looking for a way to check to see if data exists in my strFilename, if not I would like it to not return a blank image, instead utilize the space.  Here is what I got below.

 

<img src="<?php echo STR_UPLOADS_PATH . $intID . "/" . $strFilename; ?>" width="88" />

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.