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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:10:24+00:00 2026-06-04T10:10:24+00:00

I have a table as follows : <table> <thead> <th>PRODUCT TYPE</th> <th>QUANTITY</th> <th>WEIGHT</th> <th>WEIGHT

  • 0

I have a table as follows :

<table>
  <thead>
     <th>PRODUCT TYPE</th>
     <th>QUANTITY</th>
     <th>WEIGHT</th>
     <th>WEIGHT PRICE</th>
     <th>TOTAL</th>
  </thead>
  <tr>
     <td>DRINKS</td>
     <input type="hidden" name="product[]" value="1" />
     <td><input type="text" name="qty[]" /></td>
     <td>LITER</td>
     <input type="hidden" name="unitPrice[]" value="34.92" />
     <td><input type="text" name="total[]" readonly="readonly" /></td>
   </tr>
  <tr>
     <td>DRY FOODS</td>
     <input type="hidden" name="product[]" value="1" />
     <td><input type="text" name="qty[]" /></td>
     <td>KG</td>
     <input type="hidden" name="unitPrice[]" value="16.30" />
     <td><input type="text" name="total[]" readonly="readonly" /></td>
   </tr>
  <tr>
     <td>FRESH FOOD</td>
     <input type="hidden" name="product[]" value="1" />
     <td><input type="text" name="qty[]" /></td>
     <td>TON</td>
     <input type="hidden" name="unitPrice[]" value="26.45" />
     <td><input type="text" name="total[]" readonly="readonly" /></td>
   </tr>
  <tr>
     <td>SWEET CONFECTIONARY</td>
     <input type="hidden" name="product[]" value="1" />
     <td><input type="text" name="qty[]" /></td>
     <td>TON</td>
     <input type="hidden" name="unitPrice[]" value="65.10" />
     <td><input type="text" name="total[]" readonly="readonly" /></td>
   </tr>
</table>

So, here is the question :
I want to check input value qty, if qty is filled then will take the related product value. But, the important things is no required to fill all those fields. Employees can fill one field or more!

Could anybody conduct to me to how can we handle this form with PHP?

  • 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-04T10:10:25+00:00Added an answer on June 4, 2026 at 10:10 am

    Code like this is problematic because the elements of the product and qty arrays must be kept in sync, but the HTML4 (and HTML5) model for form submission does not say that these qty controls have to be successful. Therefore the browser might choose not to submit their values, which will mess up cross-array indexing.

    The cleanest solution would be to explicitly specify the indexes for the arrays in each control’s name:

      <tr>
         <td>DRINKS</td>
         <input type="hidden" name="product[0]" value="1" />
         <td><input type="text" name="qty[0]" /></td>
         <td>LITER</td>
         <input type="hidden" name="unitPrice[0]" value="34.92" />
         <td><input type="text" name="total[0]" readonly="readonly" /></td>
       </tr>
      <tr>
         <td>DRY FOODS</td>
         <input type="hidden" name="product[1]" value="1" />
         <td><input type="text" name="qty[1]" /></td>
         <td>KG</td>
         <input type="hidden" name="unitPrice[1]" value="16.30" />
         <td><input type="text" name="total[1]" readonly="readonly" /></td>
       </tr>
    

    This way you can then do

    foreach ($POST['product'] as $i => $val) {
        if (!empty($POST['qty'][$i])) {
            // the product has a nonzero quantity
        }
    }
    

    Another option that you might want to consider is this:

      <tr>
         <td>DRINKS</td>
         <input type="hidden" name="product[0][product]" value="1" />
         <td><input type="text" name="product[0][qty]" /></td>
         <td>LITER</td>
         <input type="hidden" name="product[0][unitPrice]" value="34.92" />
         <td><input type="text" name="product[0][total]" readonly="readonly" /></td>
       </tr>
    

    which would work along with

    foreach ($POST['product'] as $product) {
        if (!empty($product['qty'])) {
            // the product has a nonzero quantity
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table as follows <table id=vainTbl6 class=dtable cellpadding=3 cellspacing=1 border=0> <thead> <tr><th>check</td><th>Morphosal</th><th>goat
I have a table like follows: Potion { id, name, freq } I gave
I have a table as follows > RowID SessionID EventID RequestedURL Date > 1
I use JPA2 for the dao layer. Suppose i have a table as follows
I have a table like as follows: SoftwareName Count Country Project 15 Canada Visio
I have a HTML table as follows. I want retrieve row values from this
Suppose I have a table MEETING as follows M_DATE M_RACE_NO M_VENUE M_ATHLETE The primary
I have table 1, all_countries, as follows- id | country ------------------ 1 | USA
i have 2 tables, users and follows. table follows has a column named status.
I have three tables as follows: table 1 is called Cat1, table 2 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.