Jump to content

Recommended Posts

i can see characters instead of image using below code. i used blob data type for storing images in mysql.

 

// Performing SQL query

$query = 'SELECT Image FROM tableImages';

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

 

// Printing results in HTML

 

list($Image) = mysql_fetch_array($result);

 

 

echo $Image; //print or return image

Link to comment
https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/
Share on other sites

It seems like you've tried storing the image itself in the database. That or something else has gone wrong that i cant think of.

 

You can't store the image itself in the database, you can store a name value and then refer to it on the servers location like http://www.exa mple.com/images/img.jpg

This is hmtl page it has button and iframe when button is clicked it activate showImages.php which shows images

 

<p><form action="showImages.php" method=GET target="imageFrame" name="show_Image">

 

<input type="submit" name=sammount value="Next" size="1">

 

</form>

<iframe name="imageFrame" align="middle" height="600px" width="500px" border="1">

 

</iframe>

 

 

showImage.php has

 

$query = 'SELECT Image FROM tableImages';

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

 

// Printing results in HTML

 

list($Image) = mysql_fetch_array($result);

 

 

echo $Image; //print or return image

 

mysql

Field  Type  Function  Null  Value

imageID int(100)

Image blob Binary - do not edit (0 B)  (Max: 65,536B)

ImageDescription varchar(200)

 

 

Here is a sample script:

<?php
$id = intval($_GET['id']);
// database connection here...

$result = mysql_query("SELECT * FROM `images` WHERE `id` = ".$id." LIMIT 1", $conn) or die(mysql_error());
if(mysql_num_rows($result)>0) { 
$row = mysql_fetch_assoc($result);
header( "Content-type: ".$row['filetype']."");
echo $row['image'];
}
?>

 

id would be the image id, filetype would contain the Content-type, and image would contain the blob of the image.

 

Then in context:

<img src="showimage.php?id=1" alt="some image">

 

Again, I'd strongly recommend just using normal images, and not storing them in the db since it would most likely cause a lot of strain on a site.

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.