Home > Article > Backend Development > Get whether the check box is selected in PHP and write it to the database_PHP tutorial
Below we summarize the information about whether the check box is selected in PHP and written to the database. Friends who need to learn can refer to it.
form.html
代码如下 | 复制代码 |
Then create a program to process the form:
checkbox.php
The code is as follows | Copy code | ||||
?> |
代码如下 | 复制代码 |
$a=$_POST["s"]; |
So the program is further modified to:
checkbox.php
The code is as follows | Copy code | ||||||||||||||||
$a=$_POST["s"]; for($i=0;$i
"; } ?> The result of this execution is similar to: Option 3 is selected Option 15 selected Use javascript to do preprocessing. Multiple checkboxes with the same name still exist in the form of arrays in javascript, so before submitting the form, you can use javascript to combine the information in the checkboxes into a character array and assign it to the hidden elements in the form, and then use php in The explode function parses this array, so that the check box information can be transferred. Below are examples. Suppose there is a form like this:
This form has four checkboxes whose names are all items. When the user clicks the submit button, the checker function will be called, and if the checker returns true, the form will be submitted. If it returns false, the form will not be submitted. . The checker function here is the preprocessing function we want to write. Add the following javascript in the header section of html:
http: //www.bkjia.com/PHPjc/629008.html TechArticle Below we summarize the information about whether the check box is selected in PHP and written to the database. Friends who need to learn can refer to it. refer to. form.html code is as follows Copy code form action=checkbox.ph...
Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn Previous article:The use and precautions of $_FILES in PHP_PHP tutorialNext article:The use and precautions of $_FILES in PHP_PHP tutorial Related articlesSee more |