Php 无法使用CodeIgniter插入数据

Php 无法使用CodeIgniter插入数据,php,codeigniter,Php,Codeigniter,我正在用CodeIgniter创建一个网站,对于其中一个页面,我需要将信息插入数据库,但是每次我将信息输入表单并提交时,页面都会像提交时一样刷新,但没有任何内容进入数据库 控制器: public function insertjob() { $this->load->helper('form'); $data['title']="Add a new job"; $this->load->view("insertjob", $data); } public functio

我正在用CodeIgniter创建一个网站,对于其中一个页面,我需要将信息插入数据库,但是每次我将信息输入表单并提交时,页面都会像提交时一样刷新,但没有任何内容进入数据库

控制器:

public function insertjob()
{
$this->load->helper('form');
$data['title']="Add a new job";
$this->load->view("insertjob", $data);
}

public function addingjob()
{
$jobtype=$this->input->post('jobtype');
$jobinfo=$this->input->post('jobinfo');
$this->load->model("cmodel");
if($this->cmodel->addjob($jobtype, $jobinfo)){
    $data['msg']="New job addition successful";
}else{
    $data['msg']="There was an error please try again";
}
$this->load->view("confirmation",$data);
型号:

function addjob($jobtype,$jobinfo)
{
    $newjob=array("jobtype"=>$jobtype,"jobinfo"=>$jobinfo);
    return $this->db->insert('clientjobs', $newjob); exit;
视图:


尝试从您的型号中删除
出口

function addjob($jobtype,$jobinfo)
{
    $newjob=array("jobtype"=>$jobtype,"jobinfo"=>$jobinfo);
    return $this->db->insert('clientjobs', $newjob); 
}
它不是必需的,可能会破坏数据库类,并停止应用程序的任何执行。

这是您的问题:

echo form_open('client/insertjob'); 
如果您在浏览器中查看HTML代码,您将看到如下内容:

<form action="client/insertjob">

正如我看到的,您正在使用2个控制器功能进行发布,从第1页到第2页。“打开表单时出错。您应该将数据发布到addingjob而不是insertjob。”

echo form_open('client/addingjob'); 
将解决您的问题,但我强烈建议您使用一个控制器进行表单提交。下面的代码将发送帖子到相同的url。你可以在上面添加一些属性

<?php 
$attributes = array('class' => 'form-horizontal');
echo form_open($this->uri->uri_string(),$attributes); ?>

echo form_open('client/addingjob'); 
<?php 
$attributes = array('class' => 'form-horizontal');
echo form_open($this->uri->uri_string(),$attributes); ?>