SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2003
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting images into database

    I'am having trouble inserting images into database along with relating data. At present data is being input but there is just an empty slot in the database where the image should be. I have read and got chapter 11 of kevins book working about uploading an image, but what i want to do is insert an image relating to data and be able to retrieve the image and relating data without having to download it.

    Any ideas or advice on articles to read appreciated.

    Code:
     $sql = "INSERT INTO joesauto SET 
    year= '$_POST[year]',
    make='$_POST[make]',
    model= '$_POST[model]', 
    price= '$_POST[price]',
    picture_name ='$_POST[picture_name]'";
     
    
    exec("cp '$_POST[picture]' C:/Web Projects/images/'$_GET[picture_name]'");
    

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it looks like you have a few things wrong.

    in your query, $_POST[picture_name], should be {$_FILES['picture']['name']} if the file field is named "picture."

    and instead of exec() (the cp command isn't on Windows anyway), you should use move_uploaded_file():

    PHP Code:
    <?php

    move_uploaded_file
    ($_FILES['picture']['tmp_name'], 'C:/Web Projects/images/' $_FILES['picture']['name']);

    ?>
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •