0

I setup a comment form with the option to submit an image, I want now to display the image only if exist.

This is the php script that I have, I know it should be related to an "if" statement but I don't know how to do it

Any help would be appreciated

<?php
$dbLink = mysql_connect("xxx","xxx","xxx");
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');

$getquery=mysql_query("SELECT * FROM comment ORDER BY id DESC");

while($rows=mysql_fetch_assoc($getquery)) {
    $id=$rows['id'];
    $name=$rows['name'];
    $comment=$rows['comment'];
    echo '<b>' . $name . '</b>' . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<img src="data:image/jpeg;base64,'.base64_encode($rows['imageData'] ).'"/>' . '<br/>' . '<br/>' . '<hr size="1"/>';
}
?>

1 Answer 1

2

Just divide the echo into 3 parts

echo '<b>' . $name . '</b>' . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' ;

if(isset($rows['imageData']) && $rows['imageData'] != '') 
   echo '<img src="data:image/jpeg;base64,'.base64_encode($rows['imageData'] ).'"/>'.'<br/>' . '<br/>' ;

echo   '<hr size="1"/>';
Sign up to request clarification or add additional context in comments.

1 Comment

yes, you are right. there is a possibility of it. made the necessary edit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.