


Get whether the check box is selected in PHP and write it to the database_PHP tutorial
Jul 13, 2016 pm 05:14 PMBelow 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
代码如下 | 复制代码 |
<form action=checkbox.php method=post> <input name="s[]" type="checkbox" value="3" />3<br> <input name="s[]" type="checkbox" value="7" />7<br> <input name="s[]" type="checkbox" value="1" />1<br> <input name="s[]" type="checkbox" value="15" />15<br> <input type=submit> </form> |
Then create a program to process the form:
checkbox.php
The code is as follows | Copy code | ||||
$a=$_POST["s"]; print_r($a);
?> |
代码如下 | 复制代码 |
<?php |
So the program is further modified to:
checkbox.php
The code is as follows | Copy code | ||||||||||||||||
<?php
$a=$_POST["s"];
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:
<!-- function checker() { form1.items.value = ""; if ( !form1.item.length ) // There is only one checkbox, form1.item.length = undefined { if (form1.items.checked) form1.items.value = form1.item.value; } else { for ( i = 0 ; i < form1.item.length ; i++ ) { if ( form1.item(i).checked ) // There is a checked box in the check box { form1.items.value = form1.item(i).value; for ( j = i + 1 ; j < form1.item.length ; j++ ) { if ( form1.item(j).checked ) { form1.items.value += " "; //Use spaces as separators form1.items.value += form1.item(j).value; } } break; } } } return true; } --> </script> 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 of this Website
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
![]() Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
![]() Hot tools Tags![]() Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
![]() Hot Article Tags![]() Notepad++7.3.1Easy-to-use and free code editor ![]() SublimeText3 Chinese versionChinese version, very easy to use ![]() Zend Studio 13.0.1Powerful PHP integrated development environment ![]() Dreamweaver CS6Visual web development tools ![]() SublimeText3 Mac versionGod-level code editing software (SublimeText3) ![]() Hot Topics![]() PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian ![]() How To Set Up Visual Studio Code (VS Code) for PHP Development ![]() |