anirudhtomer Posted March 9, 2010 Share Posted March 9, 2010 hi everyone, my php code is as follows <?php $connection = mysql_connect("localhost","xxxx","xxxx"); mysql_connect_db("xxxxx",$connection); header("Content-type: text/html"); header("Content-type: image/jpg"); echo "<b> THE MOTOR DRIVING LICENSE <b>"; echo "<img src = 'pic.jpg' />"; //pic.jpg is an image at server $result = mysql_query("select image from license); $rowdata = mysql_fetch_array($result); /*** license is the name of table and image is the column with MEDIUM BLOB DATA TYPE ***/ $image = $rowdata['image']; echo $image; //browser displays random charactes instead of image ?> NOW THE OUTPUT I GET IS SOME RANDOM CHARACTERS INSTEAD OF THE IMAGE I AM EXPECTING FROM THE DATABASE. when I try to print the image just below the header defining the content type as image , then I get the name of my php file printed in my browser & nothing else Please enlighten me, where I am making a mistake & correct me. THANKS IN ADVANCE Link to comment https://forums.phpfreaks.com/topic/194649-getting-random-characters-instead-of-image-in-php/ Share on other sites More sharing options...
MadTechie Posted March 9, 2010 Share Posted March 9, 2010 What your doing makes no sence! is this an image or HTML ? Link to comment https://forums.phpfreaks.com/topic/194649-getting-random-characters-instead-of-image-in-php/#findComment-1023712 Share on other sites More sharing options...
anirudhtomer Posted March 9, 2010 Author Share Posted March 9, 2010 so please tell me how can I show image as well as html text together in a php file...Is there any way to do this Link to comment https://forums.phpfreaks.com/topic/194649-getting-random-characters-instead-of-image-in-php/#findComment-1023714 Share on other sites More sharing options...
MadTechie Posted March 9, 2010 Share Posted March 9, 2010 I assume you mean something like this echo "<b> THE MOTOR DRIVING LICENSE <b>"; echo "<img src = 'image.php' />"; //pic.jpg is an image at server <?php $connection = mysql_connect("localhost","xxxx","xxxx"); mysql_connect_db("xxxxx",$connection); header("Content-type: image/jpg"); $result = mysql_query("select image from license"); $rowdata = mysql_fetch_array($result); echo $rowdata['image']; //browser displays random charactes instead of image ?> Of course your probably want to pass a value via get (the url) to the image script to allow the database to pick up the correct image Link to comment https://forums.phpfreaks.com/topic/194649-getting-random-characters-instead-of-image-in-php/#findComment-1023718 Share on other sites More sharing options...
anirudhtomer Posted March 9, 2010 Author Share Posted March 9, 2010 well I am sending the primary key of the table via post method to select the appropriate image. that code I have not added here ... I have sent a simplified code here... so isn't it possible to print HTML text & image from database together... the problem is not how i get the image from database ... without the html part it prints the image perfectly..problem arises when use HTML text in PHP file... & even If I remove the line echo "<img src = 'pic.jpg' />"; & only keep the line echo "<b> xxxx </b>"; it is not showing any image Link to comment https://forums.phpfreaks.com/topic/194649-getting-random-characters-instead-of-image-in-php/#findComment-1023720 Share on other sites More sharing options...
anirudhtomer Posted March 9, 2010 Author Share Posted March 9, 2010 yipppeeee some success... Mad Techie as u had hinted me..I now try to print my image using another php file...& it prints successfully but now I don't know how to send the primary key of my table to that php file to select the right image ... do I have to embed it in my URL... any help Link to comment https://forums.phpfreaks.com/topic/194649-getting-random-characters-instead-of-image-in-php/#findComment-1023723 Share on other sites More sharing options...
shlumph Posted March 9, 2010 Share Posted March 9, 2010 I'd utilize the query string: <img src="get-image.php?id=123" /> Link to comment https://forums.phpfreaks.com/topic/194649-getting-random-characters-instead-of-image-in-php/#findComment-1023729 Share on other sites More sharing options...
anirudhtomer Posted March 9, 2010 Author Share Posted March 9, 2010 thanks man! the problem is solved now. Link to comment https://forums.phpfreaks.com/topic/194649-getting-random-characters-instead-of-image-in-php/#findComment-1023730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.