troubleshooting Question

Php/MySQL display a default image if the MySQL file image blob is empty

Avatar of BenzGuy
BenzGuy asked on
49 Comments2 Solutions470 ViewsLast Modified:
This should be a fairly easy question for you those of you familiar with PHP, but I am not having any luck finding an answer.  I've already search through-out EE and nothing has worked and I'm running out of time.

What I'm trying to do, is to display a default image if the MySQL file image blob is empty

Thanks in advance for any help you can provide
    if (isset($_GET['recid']))
        $recid = $_GET['recid'];
    $link = mysql_connect('localhost', 'user', 'pass');
    mysql_select_db('testing', $link);
    // Make SELECT query
    $data = mysql_fetch_array(mysql_query("SELECT `file` FROM `testing` WHERE `id` = '{$recid}'", $link), MYSQL_ASSOC);
    // Set the content type header
	header('Content-Type: image/jpg');
	header("Content-Disposition: attachment; filename=photo.jpg");
	if (!empty($data['file'])) { echo "<img src =\"<img src="nophoto.jpg" />";
	else {
    	echo $data['file'];

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 49 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 49 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros