我在数据库中插入记录时遇到问题。我的表单将一个字符串发送到必须在数据库中的模型中,该模型必须在“ obbligo”表的“ descr_ obbligo”字段中。
如标题所示,错误是:
发生数据库错误,错误号:1048列'descr_必须'不能为空”。
我的控制器:
public function insert_obbligo (){
$data['title']="Insert Dare";
if($this->input->server('REQUEST_METHOD') == "GET"){
$data['Descr_obbligo'] = "";
$this->load->view('templates/header');
$this->load->view('insert', $data);
$this->load->view('templates/footer');
}
else{
$this->index;
}
function confirm_insert_obbligo(){
$data['Descr_obbligo'] = $this->input->post('Descr_obbligo');
$this->form_validation->set_rules('Descr_obbligo' , 'Descr_obbligo' , 'required');
if($this->form_validation->run() == FALSE){
echo "errore1";
}
else{
if($this->Tom_Model->insert_obb()){
$session_data=array(
'obbligo' => $obbligo
);
redirect('tom/index');
}
else{
echo "errore2";
}
}
}
我的模特
public function insert_obb(){
$session_data = array(
'descr_obbligo' => $this->input->post('descr_obbligo')
);
return $this->db->insert('obblighi', $session_data);
}
具有以下形式的视图:
<h2><?=$title; ?></h2>
<?php echo form_open_multipart('tom/confirm_insert_obbligo'); ?>
<div class="form-group">
<input type="text" class="form-control" name="Descr_obbligo"
placeholder="Obbligo" value="">
</div>
<div class="form-group">
<div class="col-xs-3" style= 'float:right' >
<button type="submit" class="btn btn-dark">Salva</button>
</div>
</div>
那么我该如何插入我的记录?预先谢谢你
答案 0 :(得分:1)
您有一些元素问题的名字,
<input type="text" class="form-control" name="Descr_obbligo"
placeholder="Obbligo" value=""> see here->^^^^^^^^^^^^^
将其更改为
<input type="text" class="form-control" name="descr_obbligo"
placeholder="Obbligo" value="change to this here->^^^^^^^^^^^^^
元素名称在前端和php端冲突