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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:03:49+00:00 2026-06-11T23:03:49+00:00

Morning All, I have a form that I am using to add multiple rows

  • 0

Morning All,

I have a form that I am using to add multiple rows into a database at once. It all seems to be working fine, except for the checkboxes. There is one checkbox for each form row. Regardless of what order the checkboxes are ticked, the results are always returned in the same order after being submitted.

Here is the main part of the form that matters:

<tr>
<td class='border'>
<input type='text' name='rowid[]' value='".$row."' style='display:none;' />
<input type='text' name='ref[]' style='width:100%;' />
</td>
<td class='border'>
<input type='text' name='obs[]' style='width:100%;' />
</td>
<td class='border'>
<input type='text' name='act[]' style='width:100%;' />
</td>
<td class='border' align='center'>
<input type='checkbox' name='comp[]' value='Yes' />
</td>
<td class='border'>
<input type='text' name='compby[]' style='width:100%;' />
</td>
<td class='border'>
<input type='text' name='compdate[]' id='completeddate".$row."' class='completeddate' style='width:100%;' />
</td>
</tr>

This form gets submitted, and my PHP code deals with it. You can see that the very first input, is the ID of the row of the form. This is a hidden field and the value is incremented by one for each row that is displayed in the form.

Once the form is submitted, I use the below PHP to get deal with each row, one at a time

foreach($_POST['rowid'] as $key=>$rowid) {

This should basically say that for a rowid, the rest of the inputs are associated, until it gets to the next rowid.

If I were to then print say

echo $_POST['ref'][$key];

I will get the reference for the first row, and then once the loop completes and prints it again, I will get the reference for the second row, and so on.

However, if I were to put

echo $_POST['comp'][$key];

Then this is where it breaks.

Let’s say for example, that for each row I ticked the checkboxes in this order:

row 1, tick, row 2, untick, row 3, tick

If I then let the loop print out all of the checkbox values, it will display

'Yes', 'Yes', ''

But it should be in this order

'Yes', '', 'Yes'

Is this because the checkbox is normal an array anyway, and I am then putting this into another array by giving it a name of comp[]?

Is there anyway around this issue, or would I be better off having radio buttons, one for yes, and one for no?

Many thanks

Eds

  • 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-11T23:03:50+00:00Added an answer on June 11, 2026 at 11:03 pm

    The proper way to create a technical hidden field in a form is to use the hidden type. Anyway, you don’t need this field here. Instead, use $row in all fields to properly identify them:

    <tr>
    <td class='border'>
    <input type='text' name='ref[<?php echo $row; ?>]' style='width:100%;' />
    </td>
    <td class='border'>
    <input type='text' name='obs[<?php echo $row; ?>]' style='width:100%;' />
    </td>
    <td class='border'>
    <input type='text' name='act[<?php echo $row; ?>]' style='width:100%;' />
    </td>
    <td class='border' align='center'>
    <input type='checkbox' name='comp[<?php echo $row; ?>]' value='Yes' />
    </td>
    <td class='border'>
    <input type='text' name='compby[<?php echo $row; ?>]' style='width:100%;' />
    </td>
    <td class='border'>
    <input type='text' name='compdate[<?php echo $row; ?>]' id='completeddate<?php echo $row; ?>' class='completeddate' style='width:100%;' />
    </td>
    </tr>
    

    Change the loop (the rowid field no longer exists). You may loop on any of your text fields, since they will be submitted even if empty (contrary to checkboxes fields, that are submitted only when checked):

    foreach($_POST['ref'] as $key => $rowid) {
    

    Check your PHP code, there may be more things to update.

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

Sidebar

Related Questions

Good Morning All, I have loaded over 1,300 blurbs into my client's database with
Morning all, I have a php script which I have been testing, and seems
I have spend all morning trying to set up multiple cores on a SOLR
Good Morning All, I have code similar to the following try{ using(var tx =
Morning all. I have the following method that I use to to try and
Morning all, I have a simple question that I could do with some help
Good Morning All. I have a table structure (I am using SQL SERVER 2000)
Good morning, I am working on a C# winform application that is using validation
Good Morning All, I have inherited an ASP.net website that was originally started back
Good morning all, i have a new question: I'm trying to save into mysql

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.