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 8874275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:40:40+00:00 2026-06-14T18:40:40+00:00

I am submitting a form where I am updating the state id , city

  • 0

I am submitting a form where I am updating the state id, city name and city image.

When I only update the image, it works.
When I update state id and city name and want my old image to remain the same, the photo field become blank in the database.

My PHP code is like this:

 <?php 

if(isset($_POST) && $_POST['submit'] == "Update")
{
        extract($_POST);
        if($_FILES['photo'])
        {
        $cityimg = upload_file($_FILES['photo'],'cityimg/','image','N','true','thumb/', 100, 100);
        $sql = "UPDATE city SET mcid = '$mcid', city_name = '$city_name', photo = '$cityimg' WHERE cid = '$cid'";
        }
        else
        {
        $sql = "UPDATE city SET mcid = '$mcid', city_name = '$city_name' WHERE cid = '$cid'";
        }
        $result = mysql_query($sql);
        if($result)
        {
            $msg = "City Updated Successfully.";
        }
}

?>

I think that my loop is having some problem.

  • 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-06-14T18:40:42+00:00Added an answer on June 14, 2026 at 6:40 pm

    You should test if a file was uploaded in a different way. For example, this will make sure that no error occurred during the file upload (and if there was any) :

    if($_FILES['photo']['error'] == UPLOAD_ERR_OK){
        // A file was uploaded and there is no error
    }
    

    If you only want to test if no file was selected, you could use UPLOAD_ERR_NO_FILE.

    More info on file upload error messages

    This should work for you :

    <?php 
    
    if(isset($_POST) && $_POST['submit'] == "Update")
    {
            extract($_POST);
    
            // If image was uploaded
            if($_FILES['logo']['error'] == UPLOAD_ERR_OK)
            {
                $cityimg = upload_file($_FILES['photo'],'cityimg/','image','N','true','thumb/', 100, 100);
                $sql = "UPDATE city SET mcid = '$mcid', city_name = '$city_name', photo = '$cityimg' WHERE cid = '$cid'";
            }
    
            // If no image was uploaded
            else
            {
                $sql = "UPDATE city SET mcid = '$mcid', city_name = '$city_name' WHERE cid = '$cid'";
            }
            $result = mysql_query($sql);
            if($result)
            {
                $msg = "City Updated Successfully.";
            }
    }
    

    Check this post for more details

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

Sidebar

Related Questions

I'm submitting a form in JavaScript inside the onclick event of an image, the
I want to make routing for form when submitting the form, $reportRoute = new
submitting form with jQuery works $('#testform').submit(); doesn't work $('#testform').submit(function () { alert('test1'); return true;
Right now I am updating user_list List using jquery and submitting the form data
I have an order submitting form where I want to replace URL texts with
I've followed this Railscast on submitting a form via Ajax and updating a div
Upon submitting this form on my site. It send me to a page that
I'm submitting a form using an ajax request (POST method), and checking the HTTP
I've got a standard login form submitting data to a Codeigniter function to do
I am getting Error in submitting the form using AJAX and Jquery, following is

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.