[英]codeigniter add database ss
我在添加交付请求时有一个关于CodeIgniter的问题,添加时填充了后者的字段,我在名为deliver的数据库中放置了一个属性,该属性默认情况下为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
方法是否返回true或false。 如果该联系人不存在,它似乎不会继续。
从您的控制器:
if($this->your_model->add([...]) == TRUE) {
echo 'This user was added';
}
else {
echo 'The user didn\'t exist.';
}
无法检查您的代码是否确实已连接到数据库以及表结构是否有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.