我有很多复选框项目,每个员工都可以访问不同的部门。我想将检查项添加到数据库中。
如果选中,则显示门的访问权限的代码
$door1 = $_POST['door1'];
echo ' dooraccess is available for ' .$door1. '<br>';
$door2 = $_POST['door2'];
echo 'dooraccess is available for ' .$door2. '<br>';
$door3 = $_POST['door3'];
echo 'dooraccess is available for ' .$door3. '<br>';
$door4 = $_POST['door4'];
echo 'dooraccess is available for ' .$door4. '<br>';
$door5 = $_POST['door5'];
echo 'dooraccess is available for ' .$door5. '<br>';
$door6 = $_POST['door6'];
echo 'dooraccess is available for ' .$door6. '<br>';
$door7 = $_POST['door7'];
echo 'dooraccess is available for ' .$door7. '<br>';
$door8 = $_POST['door8'];
echo 'dooraccess is available for ' .$door8. '<br>';
$door9 = $_POST['door9'];
echo 'dooraccess is available for ' .$door9. '<br>';
$door10 = $_POST['door10'];
echo 'dooraccess is available for ' .$door10. '<br>';
$door11 = $_POST['door11'];
echo 'dooraccess is available for ' .$door11. '<br>';
$door12 = $_POST['door12'];
echo 'dooraccess is available for ' .$door12. '<br>';
如果未检查的值,则它将显示如下错误:
未定义的索引:[因为未检查门7]中的门7
将这些值与其他值一起插入数据库php mysql database
if(isset($_POST['submit']))
{
$query = "INSERT INTO form_details1(firstname,secondname,location,designation,fileno,doa,doj,cardtype1,cardcolor,cardtype2,door1,door2,door3,door4,door5,door6,door7,door8,door9,door10,door11,door12,door13) VALUES('$firstname','$secondname','$location','$designation','$fileno','$doa','$doj','$cardtype1',$cardcolor,'$cardtype2','$door1','$door2','$door3','$door4','$door5','$door6','$door7','$door8','$door9','$door10','$door11','$door12')"; //query
if(mysqli_query($connect,$query)){ //check query executed or not
echo 'inserted' . '<br>' ;
}
查询未插入数据库,因为查询具有未选中的值
我想使用if
循环或任何其他方式检查所有选中的项目,并仅输入已检查的项目。我怎么能这样做?
我的表格似乎是
+---------+---------+-------+ | Id | door1 | door2 | +---------+---------+-------+ | Value 1 | Value 2 | 123 | | Value 2 | NULL | 123 | +---------+---------+-------+
The uncheck box will be empty in the table .
应该是什么
mysql field datatype for array having values that has been selected
答案 0 :(得分:1)
您需要使用复选框数组。请查看此stackoverflow答案。
答案 1 :(得分:1)
将PHP代码更改为:
isWindows()
答案 2 :(得分:1)
首先检查是否设置了复选框:
var str = "Hello, playground"
let newTypeString = NSString(string: str)
然后您的查询有效:员工可以访问的门有1,其他人有0。
优化:
始终使用此处所述的参数化查询:Parameterized Query
更容易遍历您的复选框,您可以设置如下名称:
$door1 = isset($POST['door1'])? 1 : 0 ;
然后循环:
foreach($ _ POST ['门']为$ num =&gt; $ value){
}
列出项目