如何将复选框中的值插入数据库中的其他列? [英] How to insert the value on my checkbox to different column on my database?
问题描述
这是我当前的输出-
我的Ajax代码就是这样-
And my Ajax code is like this -
没有错但它无法通过我的数据库
There's no error. but it can't pass through my database
我的控制器
public function insertNewRole(){
$basic_data = array();
$basic_data = array(
'accs_trans_sec' => $_POST['select_access1'],
'accs_acctng_sec' => $_POST['select_access2'],
'accs_admin_sec' => $_POST['select_access3'],
'accs_dashboard_sec' => $_POST['select_access4'],
'accs_reports_sec' => $_POST['select_access5']
);
$this->RoleModel->saveRole($basic_data);
}
推荐答案
我只是在这里看到问题。
我看到 datastring
变量是一个字符串,每个值都用,
分隔在您的控制器上发布吧?
因此,它将是您控制器上的 $ _ POST ['data']
。
I just see the issue here.
I see that datastring
variable is an string that each value is separated by ,
that you just use to post on your controller right?
So it will be $_POST['data']
on your controller.
然后尝试在控制器上使用 explode()
:
Then try to use explode()
like this on your controller:
$ parseddata = explode(',',$ _ POST ['data']);
$parseddata = explode(',',$_POST['data']);
让我们继续您的代码:
public function insertNewRole(){
$parseddata = explode(',',$_POST['data']);
$basic_data = array();
$basic_data = array(
'accs_trans_sec' => $parseddata[0], //The value should be 1
'accs_acctng_sec' => $parseddata[1],//The value should be 0
'accs_admin_sec' => $parseddata[2], //The value should be 1
'accs_dashboard_sec' => $parseddata[3], //The value should be 0
'accs_reports_sec' => $parseddata[4] //The value should be 1
);
$result = $this->RoleModel->saveRole($basic_data);
if($result == true){
echo ("Successfully inserted!");
}else{
echo ("Problem!");
}
}
让我们看看您是否可以解决这个问题。
Let's see if you can get through this.
编辑:根据您之前的帖子,您的模型上有一个循环,我对其进行了修改,并且应该这样:
Based on your previous post, your model has a loop on it, I modify it and should like this:
public function saveRole($basic_data)
{
$this->db->insert('roles_global_access', $basic_data);
return ($this->db->affected_rows() != 1) ? false : true;
}
这篇关于如何将复选框中的值插入数据库中的其他列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!