problem with this code to show images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mostafa581
Forum Newbie
Posts: 3
Joined: Sat Apr 26, 2008 5:37 pm

problem with this code to show images

Post by mostafa581 »

friends
i,m facing a problem with showing images stored into my database according to the following
i,m building a news website which shows news and a pic related to each news
i could make a page by which i can store news and a picture with each one
i made this page wich show these news as a title ans a pic beside to each news title every thing is ok but these pics can,t be shown all i can see is a red X mark in the place of the pic although i clicked right click on the red X and saw that the source of the pic is ok with the ip of the each opic
i,m posting the code i did so any one could tell me what is wrong or missing with it

i did a page is called getimage.php
and here is the code of it

Code: Select all

<?php
 include ("config.php");
// this is to get the id of the required pic 
 $id=addslashes(@$_REQUEST['id']);
	$image= mysql_query ("SELECT photo FROM tourism_news Where id=$id");
	$row1 = mysql_fetch_assoc($image);
	$myimage= $row1['photo'];
	
	header("content-type:image/jpeg");
	//$type ='content-type:'.$row1['imagetype']; 
	  $type ="content-type:".$row1['imagetype'];  
   echo "<img src='$myimage' width='100' height='200'>";
    //header($type);
	//echo  $row1['photo'];
	echo "$myimage";
	//echo <img src=\"$myimage\">;
?>
as for the page which show these pics
the code of that part which shows the picture is as followiing

Code: Select all

echo"<img src='getimage.php?id=".$row['id']."' width=200 height=140 />"; 
i tried alot with this code but it did not work with me as a beginner and this is my first site so i,m waiting for your point of view my dear friends
Thank you
Last edited by Benjamin on Tue Oct 09, 2012 1:11 am, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: problem with this code to show images

Post by requinix »

mostafa581 wrote:i clicked right click on the red X and saw that the source of the pic is ok
You saw what you thought was okay. It's not okay.

Code: Select all

echo "<img src='$myimage' width='100' height='200'>";
echo "$myimage";
Not only are you outputting HTML with the image data (at least that's what it is), you're outputting it twice. Don't.
Post Reply