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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:23:16+00:00 2026-06-11T09:23:16+00:00

I’ve made dynamic forms that can update an entire list of options with a

  • 0

I’ve made dynamic forms that can update an entire list of options with a single submit button, using the foreach($_POST) technique, but for some reason, I am having issues achieving the same thing with checkbox inputs.

No matter which checkboxes I deselect, the script that evaluates the checkboxes and treats the final rows in the form as the ones I deselected. In other words, no matter which checkbox I deselect, the POST script will determine the final checkbox was deselected. It’s a very strange effect I’ve never seen before.

For example, this PHP array fetch generates rows of inventory items with the option to hide the item.

****Note that I have not put in the security measures yet. When I see this work logically I will sanitize everything. I don’t even want to use REQUEST at the moment, but I want to see this work first.

<form action="update.php" method="post">
while($row=mysql_fetch_array($histresult))
    {
                echo '<tr height = "50px">';
                //We grab the product id as well as everything else we need.
                $customer_id= $row['customer_id'];
                $product_id= $row['product_id'];
                $link = $row['image_path'];
                $name = $row['name'];
                $sku_item_number = $row['sku_item_number'];
                $suggested_quantity = $row['suggested_quantity'];
                $sales_info = $row['sales_info'];
                $item_id = $row['id_product_customer_suggested_qty'];
                $customer_level = $row['level'];


                //Visibility Option Goes here
                echo '<td>';
                echo '<input name="i" type="hidden" value="'.$i.'">
                <input name="product_id[]" type="hidden" value="'.$product_id.'">
                <input name="customer_id[]" type="hidden" value="'.$customer_view.'">
                <input name="customer_level[]" type="hidden" value="'.$customer_level.'">';

                echo '<input name="cart_visible[]" type="checkbox" value = "1"';
                if (!in_array($product_id, $hidden))
                {
                    echo 'checked = "checked"';
                }
                echo '></td>';
                echo '<td>';
                echo '<a href="displayitem.php?product_id='.$product_id.'">'.$name.'</a>';
                 echo '</td>';
                 echo '<td>'.$sku_item_number.'</td>';
                 echo '<td>'.$product_id.'</td>';
                 echo '<td>'.$sales_info.'</td>';
                 echo '<td>'.$suggested_quantity.'</td>';
                         echo '</tr>';
<input type="submit" name="button" id="button" value="Submit">
</form>

//And then update.php looks like this:

$j=0;
foreach($_REQUEST['product_id'] as $key=>$product_id)
{ 
    echo 'j value is '.$j.'<br>';
    $customer_id = $_REQUEST['customer_id'][$key];
    $customer_level = $_REQUEST['customer_level'][$key];
    $price_level_id = $_REQUEST['price_level_id'][$key];
    $cart_visible = $_REQUEST['cart_visible'][$key];

    if ($cart_visible != 1)
    {
        $cart_visible = 0;
    }
    //echo 'Customer ID is '.$customer_id.'<br>';
    echo 'Testing - Product ID is '.$product_id.'<br>';
    //echo 'Customer Level is '.$customer_level.'<br>';
    //echo 'Price Level ID is '.$price_level_id.'<br>';
    echo 'Cart visibility selection is '.$cart_visible.'<br>';
}

The echoing debug lines reveal that no matter which rows I deselect, it treats the final rows in the form as the ones that are deselected. For example, if there are ten rows and I deselect the checkboxes of rows 1, 3, and 8, the form will act like the user deselected the 8th, 9th and 10th checkbox. Why would it do this exclusively for checkboxes?

  • 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-11T09:23:18+00:00Added an answer on June 11, 2026 at 9:23 am

    When you post a checkbox that was deselected, it does not send its “value”, hence is not in POST.

    If the checkbox was part of an array name, and there were ten checkbox’s, 3 deselected, the resulting array in POST will simply have 7 indexs 0 to 6.

    to solve this problem, give the checkbox names a value for the array..

    I may have not properly understood your code, but something like this

    $ite=0;    
    while($row=mysql_fetch_array($histresult)){
          //....
          echo '<input name="cart_visible['.$ite.']" type="checkbox" value = "1"';
          //....
          $ite++;
    }
    

    Now, say you deselected checkbox number 3, which means the 3rd index will not be there. $cart_visible part of code should look something like this

    //if checkbox value exists, make $cart_visible to that value, else make $cart_visible to 0
    $cart_visible = isset($_REQUEST['cart_visible'][$key])?$_REQUEST['cart_visible'][$key]:0;
    

    and remove the if statement for $cart_visible

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... 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.