PHP Upload Problems - please help !!

Discussion in 'PHP' started by freebie, Nov 3, 2007.

  1. #1
    Hope someone can help...

    I am able to upload an image to the server using PHP by what I am then trying to do is to add the image name on to a MySQL database. An example of what I am trying to do is shown below:

    Form element:

    <input name="fileupload" type="file" size="50">


    PHP element:

    $insert = mysql_query("insert into table values ('$_POST[fileupload]')");

    Is it not possible to insert an image file name direct in to a MySQL database using $_POST ?

    Is there another way?

    Thanks!
     
    freebie, Nov 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Nov 3, 2007 IP
  3. freebie

    freebie Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks nico for your help...much appreciated.

    I have had a little play around (because I use more than one image to be uploaded in one form) but will try and have another play aorund to see if i can work this out.

    Do you mean:

    $insert = mysql_query("insert into table values ('$_FILES['fileupload']['name']')");

    or

    $imagename = $_FILES['fileupload']['name']

    $insert = mysql_query("insert into table values ('$imagename')");


    Cheers!
     
    freebie, Nov 3, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    The first would throw a syntax error.

    I'd do it like that
    
    $insert = mysql_query("
        INSERT INTO table
        VALUES ('" . mysql_real_escape_string($_FILES['fileupload']['name']) . "')
    ") OR die(mysql_error());
    
    PHP:
     
    nico_swd, Nov 3, 2007 IP
    birdsq likes this.