datoshway Posted March 25, 2010 Share Posted March 25, 2010 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" /> Quote Link to comment https://forums.phpfreaks.com/topic/196547-check-if-data-exists/ Share on other sites More sharing options...
jmajeremy Posted March 26, 2010 Share Posted March 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196547-check-if-data-exists/#findComment-1031958 Share on other sites More sharing options...
datoshway Posted March 26, 2010 Author Share Posted March 26, 2010 Thanks for the reply. That actually have me a syntax error. Parse error: syntax error, unexpected '{' in /news.php on line 246 Quote Link to comment https://forums.phpfreaks.com/topic/196547-check-if-data-exists/#findComment-1031961 Share on other sites More sharing options...
o3d Posted March 26, 2010 Share Posted March 26, 2010 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". Quote Link to comment https://forums.phpfreaks.com/topic/196547-check-if-data-exists/#findComment-1031967 Share on other sites More sharing options...
datoshway Posted March 26, 2010 Author Share Posted March 26, 2010 Wow. Um well this forum is for people to ask questions. So take a hike! Quote Link to comment https://forums.phpfreaks.com/topic/196547-check-if-data-exists/#findComment-1031970 Share on other sites More sharing options...
oni-kun Posted March 26, 2010 Share Posted March 26, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/196547-check-if-data-exists/#findComment-1031973 Share on other sites More sharing options...
datoshway Posted March 26, 2010 Author Share Posted March 26, 2010 Thank you Oni. Worked perfect. I'm fairly new to development, and still learning the ropes. I appreciate you taking the time to help me. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/196547-check-if-data-exists/#findComment-1031979 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.