我无法更新数据库中的数据。我不知道发生了什么事。请帮助我。显示数据按编辑按钮。但我无法更新数据库中的数据。
Controller.php这样
public function ajax_update(){
$data = array(
'festivalname' => $this->input->post('festivalname'),
'description' => $this->input->post('description'),
'dos' => $this->input->post('dos'),
'doe' => $this->input->post('doe'),
'place_id' => $this->input->post('place_id'),
'pro_id' => $this->input->post('pro_id'),
);
if($this->input->post('remove_fesimg')) // if remove photo checked
{
if(file_exists('upload/festivals/'.$this->input->post('remove_fesimg')) && $this->input->post('remove_fesimg'))
unlink('upload/festivals/'.$this->input->post('remove_fesimg'));
$data['fesimg'] = '';
}
if(!empty($_FILES['fesimg']['name']))
{
$upload = $this->_do_upload();
//delete file
$festival = $this->festivalmodel->get_by_id($this->input->post('fesid'));
if(file_exists('upload/festivals'.$festival->fesimg) && $festival->fesimg)
unlink('upload/festivals'.$festival->fesimg);
$data['fesimg'] = $upload;
}
$this->festivalmodel->update(array('fesid' => $this->input->post('fesid')), $data);
echo json_encode(array("status" => TRUE));
}
Model.php
public function update($where, $data)
{
$this->db->update('tblfestival', $data, $where);
return $this->db->affected_rows();
}
的Javascript
function save(){
if(save_method == 'add') {
url = "<?php echo site_url('index.php/festival/ajax_add')?>";
} else {
url = "<?php echo site_url('index.php/festival/ajax_update')?>";
}
// ajax adding data to database
var formData = new FormData($('#form')[0]);/**/
$.ajax({
url : url,
type: "POST",
data: formData,
contentType: false,
processData: false,
dataType: "JSON",
success: function(data)
{
if(data.status) //if success close modal and reload ajax table
{
$('#modal_form').modal('hide');
reload_table();
}
else
{
for (var i = 0; i < data.inputerror.length; i++)
{
$('[name="'+data.inputerror[i]+'"]').parent().parent().addClass('has-error'); //select parent twice to select div form-group class and add has-error class
$('[name="'+data.inputerror[i]+'"]').next().text(data.error_string[i]); //select span help-block class set text error string
}
}
$('#btnSave').text('save'); //change button text
$('#btnSave').attr('disabled',false); //set button enable
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error adding / update data');
$('#btnSave').text('save'); //change button text
$('#btnSave').attr('disabled',false); //set button enable
}
});
我按下保存按钮。但是无法更新数据,没有任何反应。我需要帮助。谢谢。