Jump to content

Recommended Posts

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

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.