controller:Test.php
public function add_proposal()
{
$roles = implode(",", $this->input->post('role'));
$data = array(
'admin_id' => $this->input->post('admin_id'),
'customer_name' => $this->input->post('customer_name'),
'purposal_name' => $this->input->post('purposal_name'),
'duration' => $this->input->post('duration'),
'role' => $roles,
);
$this->db->insert('proposal_data',$data);
$query = $this->db->insert('proposal',$data);
if($query == true)
{
echo "<meta http-equiv='refresh' content='1' />";
echo '<p style="color:green;text-align:center;">Your data save successfully</p>';
}
else
{
echo '<p style="color:red;text-align:center;">Error!</p>';
}
}
视图:
<script>
$(document).ready(function(){
$("#submit").click(function(){
admin_id = $("#admin_id").val();
customer_name = $("#customer_name").val();
purposal_name = $("#purposal_name").val();
duration = $("#duration").val();
role = $('.test').val();
$.ajax({
type:"POST",
data:{"admin_id":admin_id, "customer_name":customer_name, "purposal_name":purposal_name, "duration":duration, "role":role},
url:"<?php echo base_url('index.php/');?>test/add_proposal",
success:function(data){
$("#pro").html(data);
}
});
});
});
</script>
在这段代码中,我有一个名为test.php的控制器。在测试控制器中,我有一个名为add_proposal的函数,我想在单击时将单个表单数据插入到两个表中。在这里,我使用jquery来插入表单数据。如果我使用单个查询运行此代码然后它完美地工作但是在两个查询的情况下它无法工作。那么,我该如何解决这个问题呢?请帮帮我。
谢谢