1,105,447 Community Members

How insert image into mysql database and retrieve

Member Avatar
rcasinillo_s
Light Poster
29 posts since Jan 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Good day everyone! Anybody could give me script for uploading or inserting image into database and how to retrieve it and print it to browser

Any help would be appreciated.

Thank you in advance.

roland

Member Avatar
DanceInstructor
Posting Whiz
355 posts since Feb 2005
Reputation Points: 19 [?]
Q&As Helped to Solve: 15 [?]
Skill Endorsements: 0 [?]
 
1
 

Are you sure you really want to do that? I think that for most applications you will be better off storing the image in a folder on your webserver and adding the location/details of the image to the database.

Member Avatar
rcasinillo_s
Light Poster
29 posts since Jan 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Are you sure you really want to do that? I think that for most applications you will be better off storing the image in a folder on your webserver and adding the location/details of the image to the database.

Okey, thinks for your advice, but how can I do that, are there any configuration to be done in the server, could you give me a script for this?

Thank you.

Roland

Member Avatar
DanceInstructor
Posting Whiz
355 posts since Feb 2005
Reputation Points: 19 [?]
Q&As Helped to Solve: 15 [?]
Skill Endorsements: 0 [?]
 
0
 

I haven't tried this myself, but there is a brief tutorial here:

http://hockinson.com/index.php?s=37

Good luck.

Member Avatar
liliafan
Junior Poster
117 posts since Apr 2004
Reputation Points: 53 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

If you do decide you want to store the image in a database (there are circumstances) then use a blob datatype.

Member Avatar
DGStudios
Light Poster
31 posts since Mar 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I will agree that it is rare that you would want to do that outside of a data hosting site like that. Otherwise you can just store the url and output it however you want by calling it with php and tellting using the following code

echo '<img src ="'.$imgurl.'">';

That will output it as the image itself. Naturally you can add the formating to it. But I find that method INCREADIBY effective.

Member Avatar
web_developer
Junior Poster in Training
84 posts since Mar 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hey guys
i have problem somehow similtar to this, how to insert colored, formated text in db and retrieve it.
when i play with the font or anything of the text throught html editor, the text is not saved in db.

the text attribute is empty, what should i write as a script.

thanks

sam

Member Avatar
DGStudios
Light Poster
31 posts since Mar 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I store things in it using full text

I store it using a variable like so

$value = '<b><center><fontcolor= "blue">This is the formated text</b></center></font>';
$query = "instert into table ('$value')";
mysql_query($query);


I use formated text alot for my forum.

Also it is possible to simply output it the text using concatenated strings with php. Its up to what you're using the text for.

Member Avatar
Rhyan
Posting Whiz in Training
240 posts since Oct 2006
Reputation Points: 5 [?]
Q&As Helped to Solve: 26 [?]
Skill Endorsements: 0 [?]
 
0
 

I store things in it using full text

I store it using a variable like so

$value = '<b><center><fontcolor= "blue">This is the formated text</b></center></font>';
$query = "instert into table ('$value')";
mysql_query($query);


I use formated text alot for my forum.

Also it is possible to simply output it the text using concatenated strings with php. Its up to what you're using the text for.

This is one way, however you will be unable to use this value in another place with another color settings. Instead I would recommend you store plain text data into your database and use some simple CSS rules where you need the text to be in different color.
You can make the following:
1. Store value $formatted_text = This is the text to be returned in red.
2. Retrieve it in your php page like this:

echo '<p style="color: red">'.$formatted_text.'</p>';

and you will get it right ;)

if you want you can use a class for this statement and add a lot of other formatting stored in an external file.

In case however you have some text and you want to store only one word with formatting, you better do the following:

$formatted_text = 'This is the text with <span style="color: red;">red words</span> in the middle.';

When you retrieve it in your php like this:

echo '<p>'.$formatted_text.'</p>';

you will have a paragraph with "red words" being the only red words inside the text.

If you are not familiar with CSS go to http://www.w3schools.com/ and learn it for free from the W3C. Good luck!

Member Avatar
remiremi
Newbie Poster
10 posts since Oct 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

All u do is, use ASP. The database that I've chosen is Microsoft Access database. I could have explained it on Microsoft SQL server but I chose Access because it is inexpensive and widely available. Transition form Access to SQL Server is painless.

Member Avatar
hookedonphp
Newbie Poster
4 posts since Nov 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Having noticed quite a few hits on my website in regard to inserting images in MySQL, I expanded existing content by adding a link to a basic script used to insert images into MySQL:
http://www.hockinson.com/inserting-images-into-mysql.txt

Member Avatar
black_ip82
Newbie Poster
15 posts since Nov 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

keep getin' this message:

1. no radio button selected.

what's wrong?

Member Avatar
black_ip82
Newbie Poster
15 posts since Nov 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

just found it..

//connect to database
$link=mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>"); 
//query database
$query = "SELECT image FROM youtablename WHERE id = 10";

$result = mysql_query($query) or die('Error, query failed');
$content=mysql_result($result,0,"image");

//send pdf to requesting page
header("Content-type: application/pdf");
echo $content;

If you retrieve a .jpg file, you need use:

header("Content-type: image/jpg");

If you retrieve a .gif file, you need use:

header("Content-type: image/gif");

If you retrieve a .mid file, you need use:

header("Content-type: audio/mid");
Member Avatar
chopram
Newbie Poster
5 posts since Nov 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey people,

I am having the biggest problem with MySQL and PHP. Basically, I have a database and I would like to store images to the database (not the images directly as BLOBS, but as paths), how do I do this?

My database structure looks like this:

Database Table: Pictures
Fields:
- PicID (Type: VarChar)
- PicName (Type: VarChar)
- PicPath (Type: VarChar)

An example entry looks like this:

- PicID = 001
- PicName = SimpsonsPic
- PicPath = C:\wamp\www\Pics\Simpsons.jpg

Now, how do I make a simple PHP webpage that displays that pic?
I have this so far, but don't know what else to add:

<?php

$con=mysql_connect("localhost","root","chopra9");
$img;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("pictures", $con);
$result = mysql_query("SELECT * FROM picturecollection");
while($row = mysql_fetch_array($result));
{
//What goes here
}
mysql_close($con);
?>

Any help would really be appreciated. Ive looked on the net for a week and havent found anything good. Thanx!!!

Member Avatar
ManOnScooter
Newbie Poster
2 posts since Nov 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This will slow down ur database and this is not a good programing practice - i suggest u keep all ur files in seperate folders and from the database get the path and show it in ur application from the path.. Do let me know if you want script for this..

Member Avatar
chopram
Newbie Poster
5 posts since Nov 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This will slow down ur database and this is not a good programing practice - i suggest u keep all ur files in seperate folders and from the database get the path and show it in ur application from the path.. Do let me know if you want script for this..

What you have exactly described is what I want to do. Could you please send me the script(s) and the database designs please. And if you could please, keep the code simple, so that I can understand it.

Member Avatar
mshahin
Newbie Poster
1 post since Jun 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey, i m solved your problem, you can try it. Thankx.

<?php

$con=mysql_connect("localhost","root","chopra9");
$img;
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
  mysql_select_db("pictures", $con);
  $result = mysql_query("SELECT * FROM picturecollection");
  while($row = mysql_fetch_array($result));
  {
     echo "<img src='Pics\Simpsons.jpg'" width='50' height='50'>";
  }
  mysql_close($con);
?>
Member Avatar
prasenjitmca7
Newbie Poster
2 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

could any one help me of the answer???
thank you in advance..
Prasenjit

Member Avatar
prasenjitmca7
Newbie Poster
2 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

how i delete image from database?

Member Avatar
peter_budo
Code tags enforcer
7,935 posts since Dec 2004
Reputation Points: 2,502 [?]
Q&As Helped to Solve: 1,028 [?]
Skill Endorsements: 66 [?]
Moderator
Featured
 
0
 

could any one help me of the answer???
thank you in advance..
Prasenjit

You have reply just above your post. If you do not like that answer then do no re-open old thread and create new one

how i delete image from database?

w3schools SQL DELETE Statement

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article