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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:39:21+00:00 2026-06-11T10:39:21+00:00

i made a query to do my work. but it does that work with

  • 0

i made a query to do my work. but it does that work with some errors.

1)i have 6 image fields and some other fields in the mysql table

2)to update i use html form with 6 file upload filed and labeled as image1 image2…

3)so if i want to update only the 5th image i have to upload new image to image5 filed in form.

to update mysql table i made this query.

$image=array(
1 =>$_FILES['image1']['name'],
2 =>$_FILES['image2']['name'],
3 =>$_FILES['image3']['name'],
4 =>$_FILES['image4']['name'],
5 =>$_FILES['image5']['name'],
6 =>$_FILES['image6']['name'],
);
$i=1;
    $sql  = "UPDATE salehotel ";
    $sql .="SET"." ";
foreach($image as $value){
    if(!$value==""){    
    $sql .=  "`image".$i."`"."="."'". $value ."'".",". " ";
    $i++;
    }

}

$sql .="
      `name`='$name',
      `status`='$status',
      `type`='$type',
      `location`='$location',
      `price`='$price',
      `description`='$description'
    WHERE  
      `property_id`='$edit'
      ";

3)when i use this to update all 6 images there is no errors and it updates every thing.

4)but when i try to update single image, (ex: think if i want to update image5) either i select a file from image5 field, this query always update first image in the table.

5)i know why it happens. in my query inside the foreach loop i’m looking only for $values not equal to “”. and then increment $i. so it incremented only one time. so it update image1 either i wanted to update image5.

6) so how can i get ride of this error ?

THANKS IN ADVANCE.

  • 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-11T10:39:23+00:00Added an answer on June 11, 2026 at 10:39 am
    $_FILES['image2']['name']='zzzzzzzzzzzzzzzzzz';
    
    $image=array(
    1 =>$_FILES['image1']['name'],
    2 =>$_FILES['image2']['name'],
    3 =>$_FILES['image3']['name'],
    4 =>$_FILES['image4']['name'],
    5 =>$_FILES['image5']['name'],
    6 =>$_FILES['image6']['name'],
    );
    
    
    for ($i = 1; $i <= 6; $i++) {
    if(!empty($image[$i])){    
        $sql .=  "`image".$i."`"."="."'". $image[$i] ."'".",". " ";
        }
    }
    
    echo $sql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a form that accepts query and executes it through php. I
I have a weird problem with my mysql query syntax. I have made a
I have the following SQL query but it doesn't entirely work because it shows
I made query that accepts two parameters. Now I want to use that query
I made a query that retrieve a list of items from a database: CREATE
I have a ViewBag.People made up from a View; var query = db.Vw_INTERACTPEOPLE.Select(p =>
here are my two charts and my query. Obviously you do see that some
I have a Business Objects Web Intelligence report that is performing a distributed query
I have a poor man's replication setup that I can't do anything about. Some
I'm doing some work for a site on a shared hosting environment that has

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.