Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用for循环选择mysql列以插入多个复选框值_Php_Html_Mysql - Fatal编程技术网

Php 如何使用for循环选择mysql列以插入多个复选框值

Php 如何使用for循环选择mysql列以插入多个复选框值,php,html,mysql,Php,Html,Mysql,我有3个复选框: <input name="perm[0]" type="checkbox" value="1" /> <input name="perm[1]" type="checkbox" value="1" /> <input name="perm[2]" type="checkbox" value="1" /> 我使用for循环遍历数组,如下所示: for($i=0; $i < 3; $i++) { $perm[$i] = iss

我有3个复选框:

<input name="perm[0]" type="checkbox" value="1" />
<input name="perm[1]" type="checkbox" value="1" />
<input name="perm[2]" type="checkbox" value="1" />

我使用for循环遍历数组,如下所示:

for($i=0; $i < 3; $i++)
{
    $perm[$i] = isset($_POST[$perm][$i]) ? 1 : 0;
}
($i=0;$i<3;$i++)的

{
$perm[$i]=isset($_POST[$perm][$i])?1:0;
}
早些时候,我成功地创建了3列
uread
uwrite
usearch
。 我想将perm[0]中的数据插入到uread中,将perm[1]插入到uwrite中等等,我不知道如何使用单个insert语句


提前感谢。

根据您提供的简要信息,我希望这可以满足您的要求

     $uread = 0;$uwrite = 0; $usearch = 0; // User have not checked any thing and 0=unchecked,1=checked

     if(isset($_POST[perm[0]]))
        $uread = 1;
     if(isset($_POST[perm[1]]))
        $uwrite = 1;
     if(isset($_POST[perm[2]]))
        $usearch = 1;

//NOW insert statement    
Insert into `your-tbl-name`(uname,uwrite,usearch) values ($uread,$write,$usearch);

根据您的要求修改
insert语句

我不理解您的问题,“在每次迭代中选择相应的表列以插入值”是什么意思?@Revent我认为OP希望根据所选复选框生成具有不同列的动态查询。如果只有三个,那么为什么不在标记中使用直接名称而不是
perm[]
?如果CORRUPT的语句正确:可以将列名(作为值)和复选框名(作为键)保存在数组中,并参照所选复选框进行插入查询。
 $uread = 0;$uwrite = 0; $usearch = 0; 

 if(isset($_POST[perm[0]])==1)
    $uread = 1;
 if(isset($_POST[perm[1]])==1)
    $uwrite = 1;
 if(isset($_POST[perm[2]])==1)
    $usearch = 1;


Insert into `your-tbl-name`(uname,uwrite,usearch) values ($uread,$write,$usearch);