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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:19:36+00:00 2026-06-11T17:19:36+00:00

When I save the image and the ordered field to the db it saves

  • 0

When I save the image and the “ordered” field to the db it saves the image(s) but each of the “ordered” fields save the same value. Any ideas on how to fix it so that the “ordered” field correctly saves what value I input for each one?

For example:

image_id  |  product_id  |  ordered  |  image        |  thumbnail
--------------------------------------------------------------------
593       |  94          |  35       |  a23145b.jpg  |  a231458.jpg
--------------------------------------------------------------------
592       |  94          |  35       |  1348352.jpg  |  1348358.jpg

Here’s what I have at the moment:

    if (isset($_FILES['product_image'])) {

        $files = array();

        foreach ($_FILES['product_image'] as $key => $values) {

            foreach ($values as $i => $value)
                $files[$i][$key] = $value;

        }

        foreach ($files as $file) {

            if (!empty($file['name'])) {

                $image = $upload->upload_image($file);
                $thumb = $upload->upload_image($file);

                $values = array(
                    'product_id'    => $product_id, 
                    'image'         => $image,
                    'thumbnail'     => $thumb,
                    'ordered' =>  $_POST['ordered'][0]
                );  

                $db->insert(config_item('cart', 'table_product_images'), $values);

            }

        }

    }

And the js for the fields

var image_row = 0;

$('#add_image').click(function() {

    html  = '<tr id="image' + image_row + '">';
    html += '<td><input type="file" name="product_image[' + image_row + ']" /></td>';
    html += '<td><input type="text" name="ordered[' + image_row + ']" /></td>';
    html += '<td><a href="#" id="remove_' + image_row + '" class="remove_image button orange">Remove</a></td>';
    html += '</tr>';

    $('#images table > tbody').append(html);

    image_row++;

    return false;

});
  • 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-11T17:19:38+00:00Added an answer on June 11, 2026 at 5:19 pm

    That’s because you are using $_POST['ordered'][0]. The index should be dynamic. Change your code to:

    foreach ($files as $key => $file) {
    
            if (!empty($file['name'])) {
    
                $image = $upload->upload_image($file);
                $thumb = $upload->upload_image($file);
    
                $values = array(
                    'product_id'    => $product_id, 
                    'image'         => $image,
                    'thumbnail'     => $thumb,
                    'ordered' =>  $_POST['ordered'][$key]
                );  
    
                $db->insert(config_item('cart', 'table_product_images'), $values);
    
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created one image but problem is that when i save image from
I am trying to save multiple image using this code. But instead its saving
I am trying to disable the save image dialoge from showing on the iPhone/any
What I am doing is to save an image loaded from any source,(camera /
In Flex, I am using graphics.codec.JPEGEncoder to save image files that are edited inside
I am trying to save image to database with Create method. but when try
I'm trying to save image into sql-server using linq. I set the field type
we store image files into database as BLOB type, but i have to save
I want to save image data to my sqlite database but I can't do
I can save image to iPhone (iPhone Photo Albums \ Saved Photos) with UIImageWriteToSavedPhotosAlbum(image,

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.