Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6381527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:24:22+00:00 2026-05-25T02:24:22+00:00

I am new in php and trying to design a system, where i have

  • 0

I am new in php and trying to design a system, where i have to upload photo, delete photo from it, and edit photos . i used move_uploaded_file(); to upload photos. and unlink(); to delete photo.I did uploading and deleting photo by form successfully. But Cant find where did i go wrong with the editing.my problem is, when in the edit form,i am not giving any new photos to edit ,mysql table is updating.but when new photos are given, the form doesnt work … here is what i did..
in the sending part:

<?php
            $product=get_product_by_id($_GET['pid']);/*is a function to get product  from database*/         

        ?>
         <form enctype="multipart/form-data" action="edit_product.php?pid=<?php echo urlencode($_GET['pid']); ?>" method="post">
            <p>Product name: 
                <input type="text" name="name" value="<?php echo $product['name']?>" id="name" />
            </p>
            <p>Actual Photo:
                <input type="file" name="photo" > 
            </p>
            <p>Thumbnail Photo:
                <input type="file" name="thumb" > 
            </p>
            <p>Visible: 
                <input type="radio" name="visible" value="0" /> No
                &nbsp;
                <input type="radio" name="visible" value="1" /> Yes
            </p>
            <input type="submit" name="submit" value="Edit Product" />
        </form>

recieving part:

if (isset($_POST['submit'])) {
        $id = mysql_prep($_GET['pid']);
        $name = mysql_prep($_POST['name']);
        $visible = mysql_prep($_POST['visible']);

        if(empty($_POST['photo'])){
            $query = "UPDATE products SET 
                    name = '{$name}', 
                    visible = {$visible} 
                    WHERE id = {$id}"; 
        }
        else{

            $product=get_product_by_id($id);
            //echo $product['photo'];
            $target = "images/products/";
            $target=$target . $product['photo'];
            $target2 = "images/product_thumbs/";
            $target2=$target2 . $product['thumb'];
            unlink($target);
            unlink($target2);

            $photo=$_POST['name'].".jpg";
            $photo = mysql_prep($photo);
            $thumb=$_POST['name']."_thumb.jpg";
            $thumb = mysql_prep($thumb);


            $target = "images/products/"; 
            $target = $target .$name.".jpg";
            $target2 = "images/product_thumbs/"; 
            $target2 = $target2 .$name."_thumb.jpg";

            move_uploaded_file($_FILES['photo']['tmp_name'], $target);
            move_uploaded_file($_FILES['thumb']['tmp_name'], $target2);

           $query = "UPDATE products SET 
                        name = '{$name}', 
                        photo = '{$photo}',
                        thumb = '{$thumb}', 
                        visible = {$visible} 
                        WHERE id = {$id}"; 
        }
 }  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:24:22+00:00Added an answer on May 25, 2026 at 2:24 am

    Look, problem is in the code:

    if(empty($_POST['photo'])){
            $query = "UPDATE products SET 
                    name = '{$name}', 
                    visible = {$visible} 
                    WHERE id = {$id}"; 
        }
    

    If your form does have enctype="multipart/form-data" attribute, your file will go NOT TO $_POST array, but to $_FILES array. So every time you send new file through form to your Update script file goes to $_FILES[‘photo’] and $_POST[‘photo’] is always empty. That’s why your script just updates the table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to PHP and trying to get my head around security. I have
I'm new to PHP but come from a Java background and I'm trying to
Hey I am very new to PHP, I come from a design background, but
I'm fairly new to PHP and I am trying to return an array from
I'm fairly new to PHP and have been trying to make a simple login
I am new to php and trying to write a login function. Bit stuck
I am new to PHP and trying to learn it by creating a database
I am new to PHP and was trying to build RestFull service in PHP
I am pretty new to PHP and I am trying to make an inventory
I am new to php and I am getting this error trying to load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.