Problems with Input[type=checkbox when PHP bulk modifies data

Source: Internet
Author: User
Input[type=checkbox] I used JS to turn the value ' on ' into a convenient entry for my database of 1 and 0
$ (' input[type= ' checkbox "] '). Change (function () {    this.value ^= 1;});


The form is too complex to be posted.
Anyway, I filled in the name of all the fields. []

The question came, I except $_post["blank"; This field can be updated in batches as normal

It is not possible to update, there is a problem in the order of updates

The following is a detailed test, such as 5 data on the page can be modified in bulk

1. Id1~5 setting $_post["blank"] = 1 (tick)
Success
2. Id1~5 setting $_post["blank"] = 0 (no tick)
Success

3. Set the ID 2,3 $_post["blank"] = 1

ID will become 1 instead of 3 unchanged

4. Try again ... Set the ID 3,4,5 $_post["blank"] = 1 (set all back to 0 in advance)

As expected, ID-A-ID4 changed to blank = 1, while the 5 did not change


Theoretically, PHP is aware of how many of my settings are set to blank = 1, but the end is only Sort Frontis set to 1

Does it feel like an array pointer is wrong? But why are other fields very accurate and normal to update the changes? Only this column cannot be modified?

The most annoying thing is knowing how to make a mistake, but can't find the reason



if (Isset ($_post["Edit_menu")) {    $gid =$_post["GID"];    $sql = "";    $menuCount = count ($_post["id"]);    for ($i =0; $i < $menuCount; $i + +) {        $title = $_post["title"];        $url = $_post["url"];        $id = $_post["id"];        $blank = $_post["blank"];        $sql. = "UPDATE ' menu ' Set                         title= '". $title [$i]. "',                        url= '". $url [$i]. "',                        blank= '". $blank [$i]. "'                    WHERE id= '." $id [$i]. "' and gid = ' $gid ';";    }    $stmt = $pdo->exec ($sql);}


Reply to discussion (solution)

Checkboxes that are not checked will not be submitted!
PHP only knows how many checkboxes are selected, but does not know which ones are selected
So you need to identify the selected checkbox by specifying the value of the checkbox instead of letting him do 0, 1 conversions
Checkbox.value is usually the ordinal or ID of an alternative

Checkboxes that are not checked will not be submitted!
PHP only knows how many checkboxes are selected, but does not know which ones are selected
So you need to identify the selected checkbox by specifying the value of the checkbox instead of letting him do 0, 1 conversions
Checkbox.value is usually the ordinal or ID of an alternative


I use a checkbox to give the user the option of selecting this item (record) when writing to SQL, setting whether a new page opens

Because it is in the list to modify the user, it seems that only this option (with a checkbox)

If not 1/0 I received is on/' Null '

The result is 1/0 the same.

What are the other solutions?

Is it possible to resolve on the client?
Hook, put target= "_blank", write into the corresponding link property inside,

$ (' input[type= ' checkbox "] '). Click (function () {            var link_id,checkbox_id;            checkbox_id= $this. ID;            The ID of the current check box is assigned to checkbox_id, converted to the ID of the corresponding link, assigned to link_id, and then            $ (link_id). attr (  "target",                                     ($ (checkbox_id). value== ' 1 ')? " _blank ":" _self "                                 );});

Is it possible to resolve on the client?
Hook, put target= "_blank", write into the corresponding link property inside,

$ (' input[type= ' checkbox "] '). Click (function () {            var link_id,checkbox_id;            checkbox_id= $this. ID;            The ID of the current check box is assigned to checkbox_id, converted to the ID of the corresponding link, assigned to link_id, and then            $ (link_id). attr (  "target",                                     ($ (checkbox_id). value== ' 1 ')? " _blank ":" _self "                                 );});



I was going to save the _blank to the database

Call to the foreground, this is a background bulk modification page

The problem is that no matter what I change the value of the checkbox, as long as there is no tick, HTML ($_post) does not send any values to the PHP processing

The nagging brother is right,
Check boxes are not used in this way,
Instead of checking or unchecked its value will change, the label will have a property checked= "checked" when it is selected.

The value of the check box is used for positioning. You change the value of the check box to the same as the ID.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.