PHP check box selected and written to database

Source: Internet
Author: User
The following figure shows the pipeline instance code: formactioncheckbox. phpnbsp... we have summarized the following information about whether to select and write the check box in PHP to the database. For more information, see.

The form.html instance code is as follows:


Then create a program to process the form:

The checkbox. php instance code is as follows:

 

However, the above program is only used to show whether the check box is normal. If all the data in the array is retrieved one by one, a loop is required. Therefore, the program is further modified:

The checkbox. php instance code is as follows:

 ";}?>

The execution result is similar:

Option 3 selected

Option 15 selected

Use javascript for preprocessing. multiple check boxes with the same name exist in javascript as arrays. Therefore, before submitting a form, you can use javascript to combine the information groups in the check box into a character array and assign values to the hidden elements in the form, then, use the explode function in php to parse the array, so that the check box information can be passed. the following is an example.

Suppose there is a form:

The instance code is as follows:


This form has four check boxes whose names are item. when you click the submit button, the checker function will be called, and if the checker returns the true form, it will be submitted, if the return value is false, the form will not be submitted. here, the checker function is the preprocessing function to be compiled. add the following javascript in the html header section:

The instance code is as follows:

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.