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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:31:53+00:00 2026-06-07T08:31:53+00:00

I have a table with an unknown number of rows. I’m trying to save

  • 0

I have a table with an unknown number of rows. I’m trying to save edits to a checkbox field, select field and text field.

Here’s a sample of what a table row looks like (generalized):

<tr onMouseover="this.bgColor='#EEEEEE'"onMouseout="this.bgColor='#FFFFFF'">
    <input type="hidden" name="batchupdate[][item1]" value="118">
    <td><a target="blank" href="www.link.com">Link</a></td>
    <td>Name</td>
    <td><input value="" type="text" name="batchupdate[][item2]" size=35></td>
    <td>
        <select name="batchupdate[][item3]">
        <optgroup label="Group 1">
            <option >1</option>
            <option >2</option>
            <option >3</option>
            <option >4</option>
            <option >5</option>
        </optgroup>
        <optgroup label="Group 2">
            <option >6</option>
            <option >7</option>
            <option >8</option>
            <option >9</option>
        </optgroup>
        </select>                           
    </td>
    <td><input type="checkbox" value="FALSE" name="batchupdate[][item4]"></td>
</tr>

The “id” (item1) is the auto incrementing field in my postgresql database.

Here’s the php:

if(isset($_POST['savebutton'])) {
    if(isset($_POST['bachtupdate']) || is_array($_POST['batchupdate']))
    {
        foreach($_POST['batchupdate'] as $i)
        {   
            $item1 = $i['item1'];
            $item2 = $i['item2'];
            $item2 = pg_escape_string($item2);
            $item3 = $i['item3'];

            if(isset($i['item4'])){
                $item4 = "TRUE";
            } else {
                $item4 = "FALSE";
            }

        $query = "UPDATE schema.table SET field2='$item2', field3='$item3', field4='$item4' WHERE id='$item1'";

        $result = pg_query($database, $query);

        if ($result) {
            // success
        } else {
            die("Error: " .pg_last_error());
        }

There’s some other logic after this, but the query part is where it fails. I get an error that basically item3 and the id (item1) are empty, so it cannot find the row to update. Items2 and 4 work fine and I can see what they contain in the error message provided by postgres.

I found this solution online and adapted it to my own use. I’m just confused as to why some of the fields work and others don’t. Ideas?

EDIT:

This is what the output looks like with echoes (inside the foreach loop). I commented out the postgres query. Notice that it does it twice. I also noticed that the checkbox isn’t returning true. However, all the information is there…,

118 (id),
Text box 1,
Option 2,
FALSE (checkbox)

119 (id),
Text box 2,
Option 3

118 (id),
Text box 1,
Option 2,
FALSE (checkbox)

119 (id),
Text box 2,
Option 3

EDIT:

Next I’m going to try one of the following:

  1. Use php to create name attributes that are unique (item11, item12, item13, etc), and increment a for loop that counts how many rows in the table there are, change the variables and perform the query. This seems way too messy, but I can’t think of anything else…,

  2. Instead of doing a foreach, do a for loop as seen in other examples I’ve found. Not sure what it will change, but it’s worth a shot I guess.

I’ll report back what I found.

  • 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-07T08:31:56+00:00Added an answer on June 7, 2026 at 8:31 am

    How generalized is the HTML you show?

    I mean, when you write

     <input type="hidden" name="batchupdate[][item1]" value="118">
    

    You do place something in the first key of batchupdate, do you not?

    Because otherwise the POST will send out, say,

    batchupdate[][item1]=118&batchupdate[][item3]=124...
    

    which will create TWO DIFFERENT ROWS in batchupdate[], one with item1, the other with only item3, since [] is autoincrement syntax.

    Each “group” of rows should have a different ID as the first index:

     <input type="hidden" name="batchupdate[row1][item1]" value="118">
     <input type="hidden" name="batchupdate[row1][item2]" value="119">
     <input type="hidden" name="batchupdate[row1][item3]" value="120">
     ...
     <input type="hidden" name="batchupdate[row2][item1]" value="123">
    

    This will result in one entry of batchupdate with item1,2 and 3 defined and equal to 118, 119, and 120, which seems what you are looking for.

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

Sidebar

Related Questions

Have JSP page with dynamically generated HTML table with unknown number of rows. Have
This is the problem: I have a table with unknown number of columns. all
I have a table that, some of its columns are unknown at compile time.
I have table with around 70 000 rows. There is 6000 rows that i
I have table in which I am inserting rows for employee but next time
I have table of data that is sorted as follows: Item | Sample |
I have table like this: id number value 1 300 233 2 343 434
I have 60 columns and unknown rows. I'm getting the datas continuously such as
Let's say, in theory, I have a database with an unknown number of tables,
I have a fixed size container with an unknown number of self sizing paragraphs

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.