Personal Car Finance - Loans - Flights - Credit Card - Buy Anything On eBay

PDA

View Full Version : How to insert and image to my database ?


Rod123
Oct 27th 2005, 8:14 am
I'm creating a Database where I have a big list of products and my

client wants to have a picture of each product. The info of the

products are on Mysql already:

id:
category:
model:
picture:
description:
application:


My Client wants to have a section to Add-products, Modify-products,

and Erase-products which I already did, but I'm having troubles to

insert the image of each product on the products table, that the

clients will see.

When I add a product I go to my add-product.php where I have my

fields:

category: new category
model: new model
picture: image2.jpg
description: new description
application: new aplication

And on my products.php will show just my table with the text, in this

case on my picture field will just show "image2.jpg" The big question

here is:

How can I insert my picture on my table from my Add-product.php?

here is the code from Add-product.php that insert the information I

add:

$category=$_POST['category'];
$model=$_POST['model'];
$picture=$_POST['picture'];
$description=$_POST['description'];
$application=$_POST['application'];
$sql = "INSERT INTO client_products VALUES ('', '$category', '$model',

'$picture', '$description', '$application');";
mysql_query($sql, $conn) or die (mysql_error());

header("locationroducts.php");

----------------------------------------------------------------------

----------------------------

Here is the php code to insert the products on "products.php":

$conn = mysql_connect("mysql.dns77.com", "client", "password") or die

(mysql_error());
mysql_select_db("client",$conn) or die(mysql_error());
$sql = "SELECT * FROM client_products ORDER BY 'id' ASC";
$result = mysql_query($sql, $conn) or die (mysql_error());
while ($cherche = mysql_fetch_array($result)) {
$id = $cherche['id'];
$categorie = $cherche['categorie'];
$model = $cherche['model'];
$picture = $cherche['picture'];
$description = $cherche['description'];
$application = $cherche['application'];

echo "<tr>
<td><table width='600' border='1' cellspacing='0' cellpadding='0'>
<tr>
<td width='80' height='100' align='center'><span

class='style4'>$categorie</span></td>
<td width='80' height='100' align='center'><span

class='style4'>$model</span></td>
<td width='100' height='100' align='center'><span

class='style4'>$picture</span></td>
<td width='140' height='100' align='center'><span

class='style4'>$description</span></td>
<td width='120' height='100' align='center'><span

class='style4'>$application</span></td>
</tr>
</table></td>
</tr>";
}
echo "</table>"."<br />";


Please I'll appreciate your help.

Rod.

TheHoff
Oct 27th 2005, 8:16 am
Save the trouble.. unless you have very sensitive photos that you want to restrict access to, just put the photos in the normal file system. In the database, put a reference to the filename. It is faster, easier, and your user's will be able to cache the photos (IE will not cache a dynamic image link).

omgitapro
Oct 27th 2005, 10:05 pm
or u can try finding script for it

DPTony
Oct 29th 2005, 8:17 pm
You can insert it by the BLOB function in MYSQL it stores the acutal image in the database or you could make it so it auto uploads into a folder link /images and have the picture part in the database store the link

Bibofa
Oct 30th 2005, 12:37 am
I wish I can help you : )

dave487
Nov 1st 2005, 8:22 am
Save the trouble.. unless you have very sensitive photos that you want to restrict access to, just put the photos in the normal file system. In the database, put a reference to the filename. It is faster, easier, and your user's will be able to cache the photos (IE will not cache a dynamic image link).

I agree, see
www.sitepoint.com/article/php-gallery-system-minutes
and
www.sitepoint.com/article/php-gd-libraries for some good tutorials on uploading images and creating square thumbnails of your product images.

PM me if you want a the full script for this.......

livingearth
Nov 1st 2005, 10:59 am
I would place the pics in regular file format in a directory of their own and just input the filename of the image into the MySQL database. You can then use that file name to complete the file path to the images when you need to display them....

livingearth
Nov 1st 2005, 11:04 am
You may also want to add a file input to your add product.php file. It will a browse button to the page so you can upload the image to your images dir. If you need some source code PM me and I see if I can send you an example...