1.11M Members

How insert image into mysql database and retrieve

 
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

 
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.

 
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

 
0
 

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

 
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.

 
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

 
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.

 
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!

 
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.

 
0
 

keep getin' this message:

1. no radio button selected.

what's wrong?

 
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");
 
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!!!

 
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..

 
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.

 
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);
?>
 
0
 

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

 
0
 

how i delete image from database?

 
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 six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article