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

  • Home
  • SEARCH
  • 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 8438049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:36:04+00:00 2026-06-10T07:36:04+00:00

I have the following table that fetches data from the database: while($row = mysql_fetch_array($result))

  • 0

I have the following table that fetches data from the database:

while($row = mysql_fetch_array($result)) 
{
echo '
    <tr>
        <td width="320">
            <input type="checkbox" name="product_ID[]" value="'.$row['Product_ID'].'" />'.$row['Product_description'].'<br />
        </td>
        <td width="50">
            <input type="text" name="product_cost[]" value="'.$row['Product_Retail_cost'].'" maxlength="3" size="3" />
        </td>
        <td width="50">
            <input type="text" name="product_quantity[]" value="1" maxlength="3" size="1" />
        </td>
    </tr>';
}

What I would like to do, is insert the row into a table, making sure to insert any updated values from the two text boxes. The insert looks like this:

$product_ID = $_POST['product_ID'];
$product_cost = $_POST['product_cost'];
$product_quantity = $_POST['product_quantity'];

for ($i=0; $i<sizeof($product_ID);$i++)
    {
    $query="INSERT INTO mjj_ordered_products 
                (`Order_ID`, 
                `Product_ID`, 
                `Product_Quantity`, 
                `Product_Price`)
    VALUES ((SELECT MAX(Order_ID) AS Order_ID FROM `mjj_orders`),
                '".$product_ID[$i]."',
                '".$product_quantity[$i]."',
                '".$product_cost[$i]."')";
    mysql_query($query) or die (mysql_error());
    }

But while this inserts the correct Product_ID, the remaining two values inserted do not correspond to the selected checkbox, but rather by looping through the entire list.

The question: how do I insert the other 2 values associated to the checkbox into the databse?

  • 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-10T07:36:05+00:00Added an answer on June 10, 2026 at 7:36 am

    Assuming the Product_ID is unique, you can pass it as the index in all arrays like

    <input type="text" name="product_cost['.$row['Product_ID'].']" value="'.$row['Product_Retail_cost'].'" maxlength="3" size="3" />
    

    And then do something like

    foreach($product_ID as $id)
    {
      $query="INSERT INTO mjj_ordered_products 
                    (`Order_ID`, 
                    `Product_ID`, 
                    `Product_Quantity`, 
                    `Product_Price`)
        VALUES ((SELECT MAX(Order_ID) AS Order_ID FROM `mjj_orders`),
                    '".$product_ID[$id]."',
                    '".$product_quantity[$id]."',
                    '".$product_cost[$id]."')";
        mysql_query($query) or die (mysql_error());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table that I insert data with following query (from c# code): INSERT
I have the following sql query that fetches images from an establishment table. The
I have the following table template that is rendered through knockout: <table class=gv data-bind=visible:
I have some data in a table that looks roughly like the following: table
I have a server-side php-script that fetches results from a MySQL table. I am
I have the following table that lists all awarded cups: Name: Cups Columns: Month,
I have a following table using MVC that shows number of items the user
The idea is that say you have the following table. ------------- | oID |
I have the following Table elements how do i run a query that reproduce
I have the following table, Persons_Companies , that shows a relation between persons and

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.