How to insert and image to my database ?

Discussion in 'MySQL' started by Rod123, Oct 27, 2005.

  1. #1
    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.
     
    Rod123, Oct 27, 2005 IP
  2. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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).
     
    TheHoff, Oct 27, 2005 IP
  3. omgitapro

    omgitapro Banned

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or u can try finding script for it
     
    omgitapro, Oct 27, 2005 IP
  4. DPTony

    DPTony Peon

    Messages:
    329
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    DPTony, Oct 29, 2005 IP
  5. Bibofa

    Bibofa Peon

    Messages:
    100
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I wish I can help you : )
     
    Bibofa, Oct 30, 2005 IP
  6. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.......
     
    dave487, Nov 1, 2005 IP
  7. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #7
    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 1, 2005 IP
  8. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #8
    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...
     
    livingearth, Nov 1, 2005 IP