php - image not displayed from database, shows only unusual fonts -


i have been trying display image database shows unusual fonts in place of image. have tried code:

$db = new mysqli("localhost", "root", "", "learndb"); $stmt=$db->prepare("select * studentrecords id=?"); $stmt->bind_param("i",$id); $stmt->execute(); $result=$stmt->get_result(); $myrow = $result->fetch_assoc(); echo '<img src="'.$myrow["image-data"].'" >'; 

your solution in this link here, should add:

echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ).'"/>'; 

into code:

$db = mysqli_connect("localhost","root","","dbname"); //keep db name $sql = "select * studentrecords id=$id"; $sth = $db->query($sql); $result=mysqli_fetch_array($sth); echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ).'"/>'; 

so in case:

$db = mysql_connect("localhost", "root", ""); mysql_select_db("learndb",$db); $result = mysql_query("select * studentrecords id=$id",$db); $myrow = mysql_fetch_array($result); echo '<img src="data:image/jpeg;base64,'.base64_encode( $myrow['image-data'] ).'"/>' 

and try not use mysql anymore, can use mysqli or pdo.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -