php - Getting the image file into the file field while updating record

699
if(isset($_GET['edit']))
{
$Id=$_GET['edit'];
//Get Form Data from Data base against the Id
$Edit_Query="SELECT * FROM products WHERE id='$Id'";
$Result=mysql_query($Edit_Query);    
while($Row=mysql_fetch_array($Result))
    {
        $Id=$Row['id'];
        $Product_Name=$Row['product_name'];
        $Product_Price=$Row['price'];
        $Product_Details=$Row['details'];
        $Category=$Row['category'];
        $Subcategory=$Row['subcategory'];
        $File_Name=$Row['product_picture']; 
    }

Now I echoed all variable into my input fields... Please note that['product_picture'] is the file name only ... physical file is uploaded in to my uploads folder... Now i want to get that physical file automatically into my file field...so if user just change other fields and hit update button ... it will update the rest of the record and file should be remained as it is in the folder as well as db with that particular$ID.

I tried<input type="file" name="product_picture" value="<php echo $File_Name; ?>"> but it is not even echoing the file name....

In simple words its like User want to update the record but its not necessary that he must have to update the file too.... it should be on choice ..

816

Answer

Solution:

Try this,

Use a hidden field to store the image ID in,

<input type="hidden" name="image_id" value="image_id">

Then you can use it to assign the new image the previous ID and not have to update the SQL database.

People are also looking for solutions to the problem: php - Mediawiki stopping a page from saving and redirecting back to edit page with an error message

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.