iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > Putting it Together > Databases

Reply
 
LinkBack Thread Tools
Old October 10th, 2008, 10:49 AM   #1
New Member
 

Join Date: Sep 2008
Location: Wales
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 twmprys is on a distinguished road
Can't get images in mysql database to display

I've inserted images into a database, but can't get them to display. I wonder if someone could help? All I get on the screen are question marks where the images should be.

This is the script:
Code:
<HTML
<BODY> 
<?php
$host
='localhost';
$username='username';
$password='password';
$db='database';

mysql_connect($host,$username,$password) or die("Unable to connect to SQL server"); 
@
mysql_select_db($db) or die("Unable to select database"); 
$result=mysql_query("SELECT * FROM images") or die("Can't Perform Query"); 
While(
$row=mysql_fetch_object($result)) { 
echo 
"<IMG SRC=\"SecondType.php3?PicNum=$row->PicNum\">"

?> 
</BODY> 
</HTML>
Then there's another script on a separate page:
Code:
<?php 
mysql_connect
($host,$username,$password) or die("Unable to connect to SQL server"); 
@
mysql_select_db($db) or die("Unable to select database"); 
$result=mysql_query("SELECT * FROM Images WHERE PicNum=$PicNum") or die("Can't perform Query"); 
$row=mysql_fetch_object($result); 
Header"Content-type: image/gif"); 
echo 
$row->Image
?>

Last edited by Aso; December 19th, 2008 at 05:25 AM..
twmprys is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 10th, 2008, 12:57 PM   #2
Rob
Elite Veteran
SuperMember
 
Rob's Avatar
 

Join Date: Jul 2003
Location: Southern UK
Age: 35
Posts: 3,131
Blog Entries: 7
Thanks: 28
Thanked 22 Times in 19 Posts
Rep Altering Power: 0 Rob is a jewel in the rough Rob is a jewel in the rough Rob is a jewel in the rough
Re: Can't get images in mysql database to display

I would never actually store a binary file in a database...

Instead of physically storing the images in the database, store them on the filesystem and store the file location (path to the image) in the database.

Storing images in a DB creates a huge overhead and can potentially slow a site right down.

Storing just the path to the file will negate the need for an additional page to pull out the image as you could just reference it with a standard image tag. You will also not have to expose a possible point of system compromise by letting everyone know the location of an image handler which is geared up for database retrieval.
__________________
Rob - Webforumz Founder

I am currently NOT available for SEO consultancy work

My Sites: Student Midwife Forum, Costa Luz Holiday Rentals
Rob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 10th, 2008, 01:11 PM   #3
New Member
 

Join Date: Sep 2008
Location: Wales
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 twmprys is on a distinguished road
Re: Can't get images in mysql database to display

Yes, I've read arguments both ways about this. Nevertheless, these are only small images, and I'm trying to construct a very simple interface to enable the site owner to make limited updates to text and pictures on their site.
twmprys is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 16th, 2008, 08:52 PM   #4
New Member
 

Join Date: Sep 2008
Location: ohio
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 jrja is on a distinguished road
Re: Can't get images in mysql database to display

images in a database - not a good idea

anyway, do you need to give the images sizes? getimagesize()

and here - don't you need to break the quotes and concatinate some of this:

echo "<IMG SRC=\"SecondType.php3?PicNum=$row->PicNum\">";

echo "<IMG SRC=\"SecondType.php3?PicNum=\"" . $row->$PicNum . "\">";

Last edited by jrja; October 16th, 2008 at 09:02 PM..
jrja is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 17th, 2008, 04:34 PM   #5
Reputable Member
 

Join Date: May 2006
Location: Warrington, UK
Posts: 434
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Accurax is on a distinguished road
Re: Can't get images in mysql database to display

Quote:
Originally Posted by twmprys View Post
Yes, I've read arguments both ways about this. Nevertheless, these are only small images, and I'm trying to construct a very simple interface to enable the site owner to make limited updates to text and pictures on their site.
Im suprised youve read anything supporting an image actually stored in a database.... unless its a desktop environment where DB overhead isnt an issue... and even then its not the best idea.

Allways store the path and simply upload the image to the relevant directory.

if your using php (i suspect you are) look into the GD Library... this is a series of php functions that allow you to resize, rename and generally edit imagess on the fly as its uploaded by the user... you can even add watermarks on the fly. it's pretty simple to use if you have a basic php understanding, and will give you exactly what your looking for.

I think the GD lib is actually included in php5 aswell .... but dont quote me on that.
Accurax is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 17th, 2008, 04:35 PM   #6
Reputable Member
 

Join Date: May 2006
Location: Warrington, UK
Posts: 434
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Accurax is on a distinguished road
Re: Can't get images in mysql database to display

Quote:
Originally Posted by jrja View Post
echo "<IMG SRC=\"SecondType.php3?PicNum=\"" . $row->$PicNum . "\">";

exactly.... except... dont use CAPS in your tag names.... bad form !!
Accurax is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Display data from database as bullet points aminah_azad PHP 12 October 15th, 2008 12:44 PM
Display different images? sing2trees Classic ASP 6 January 16th, 2008 01:15 AM
The Best way to display Images and text thewebkid How is this done? 7 November 19th, 2007 09:56 AM
display first only part of a database record. Daddyohhh99 Other Languages 0 February 3rd, 2006 10:49 AM
display web address with link from database! Monie Classic ASP 3 August 29th, 2004 09:39 AM


Search Engine Optimization by vBSEO 3.2.0 RC8