After Selecting a jpg image from a MySQL server when I try to echo it in a separate division it comes out as a jumble of ascii characters when I use this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="image/jpeg; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<div id = "myDiv">
<h2>Div</h2>
<?php
require_once('appvars.php');
require_once('connectvars.php');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$id = 1;
$query = "SELECT image FROM images WHERE id=?";
$stmt = $dbc->prepare($query);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($image);
$stmt->fetch();
echo $image;
?>
</div>
</body>
</html>
Thanks in advance for the help!
The browser does not understand that its an image within the “div” where you’re echoing. You’ll have to make this PHP script separate and use
<div><img src="/path/to/script.php"></div>. That would tell the browser that the content is an image.