Skip to main content
Known Participant
March 2, 2010
Question

Problems with updating an uploaded picture.

  • March 2, 2010
  • 1 reply
  • 257 views

I have a problem with changing a picture for a record in a database.

Basically a picture is uploaded to an upload folder and the filename stored in the database.

Inserting/viewing the picture is fine but I have now included a separate update program and the ($_FILES["PictureLocation"]) is never set, even though it has virtually the same code as the insert program.

All other fields are updated fine.

I have included code for both the check for $_FILES["PictureLocation"] and the setting up of  $_FILES["PictureLocation"] for both the INSERT and UPDATE functions.

Why is $_FILES["PictureLocation"] not set in the update program??

INSERT CODE........

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{

     //Сheck that we have a file
     if((!empty($_FILES["PictureLocation"])) && ($_FILES['PictureLocation']['error'] == 0))
    {

          // copy file to upload folder + add filename to database.

       <tr>
              <td align="right" nowrap="nowrap"><strong>PictureLocation:</strong></td>
              <td bgcolor="#CCFFCC"><input type="file" name="PictureLocation" value="" size="20" /></td>
              <td> </td>
              <td bgcolor="#FFFFFF"> </td>
            </tr>

UPDATE CODE.......

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form4"))

{

         //Сheck that we have a file
        if((!empty($_FILES["PictureLocation"])) && ($_FILES['PictureLocation']['error'] == 0))
         {    

       // copy file to upload folder + add filename to database.

  <tr valign="baseline">
              <td nowrap="nowrap" align="right"><strong>Picture</strong></td>
              <td bgcolor="#CCFFCC"><input type="file" name="PictureLocation" value="" size="20" /></td>
              <td bgcolor="#CCFFFF"> </td>
            </tr>

This topic has been closed for replies.

1 reply

harkusaAuthor
Known Participant
March 2, 2010

I have now resolve this    

The enctype="multipart/form-data"was missing

  <form action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="post" name="form4" id="form4">