Codeigniter添加数据库ss


codeigniter add database ss

我有一个关于CodeIgniter的问题当我添加一个交付请求并在添加时填充后者的字段时,我在数据库中添加了一个名为deliver的属性,默认值为0,这是自动添加的,但是由于我不能添加request

我如何添加一个应用程序和交付价值是自动添加数据库与值为0在每次添加

下面是我使用的一些代码:

function add($name, $email, $phone, $depart, $arrivee, $capacite, $livrer, $uid)
{
    $query = $this->db->get_where('contacts', array(
        'name' => $name,
        'uid' => $uid
    ));
    if ($query->num_rows == 1)
    {
        return FALSE;
    }
    $this->db->insert('contacts', array(
        'name' => $name,
        'email' => $email,
        'phone' => $phone,
        'depart' => $depart,
        'arrivee' => $arrivee,
        'capacite' => $capacite,
        'livrer' => 0,
        'uid' => $uid
    ));
    $this->db->set('contacts', 'contacts+1', FALSE)->where('uid', $uid)->update('users');
    return TRUE;
}

}

public function add_contact()
{
    sleep(1);
    $this->load->library('form_validation');
    $this->form_validation->set_rules('name', 'Name', 'required|max_length[40]|callback_alpha_dash_space');
    $this->form_validation->set_rules('email', 'Email', 'required|max_length[40]|valid_email');
    $this->form_validation->set_rules('phone', 'Phone', 'required|max_length[8]|alpha_numeric');
    $this->form_validation->set_rules('depart', 'Depart', 'required|max_length[15]|trim');
    $this->form_validation->set_rules('arrivee', 'Arrivee', 'required|max_length[15]|trim');
    $this->form_validation->set_rules('capacite', 'Capacite', 'required|max_length[15]|trim');

    if ($this->form_validation->run() == FALSE) {
        $message = "<strong>ajout</strong> echoué!";
        $this->json_response(FALSE, $message);
    } else {
        $is_added = $this->contact_model->add($this->input->post('name'), $this->input->post('email'), 
            $this->input->post('phone'),$this->input->post('depart'),$this->input->post('arrivee'),$this->input->post('capacite'), $this->session->userdata('uid'));
        if ($is_added) {
            $message = "<strong>".$this->input->post('name')."</strong> a été ajouté!";
            $this->json_response(TRUE, $message);
        } else {
            $message = "<strong>".$this->input->post('name')."</strong> existe deja!";
            $this->json_response(FALSE, $message);
        }
    }
}

检查您的add方法是否返回真或假。如果联系人不存在,似乎不会继续。

从你的控制器:

if($this->your_model->add([...]) == TRUE) {
 echo 'This user was added';
}
else {
 echo 'The user didn''t exist.';
}

检查代码是否连接到数据库,表结构是否有效