Unknown column ‘response’ in ‘field list’ UPDATE `coach` SET `response`=’error’,`message`=’ The filetype you are attempting to upload is not allowed

  ajax, codeigniter, database, jquery, php

My Controller Code

    public function UpdateCoach()
    {
      if($this->session->userdata('email')=="" && $this->session->userdata('password')=="")
      {
           $this->load->view('Admin/index');
      }
      else if($this->input->is_ajax_request())
      {
         $this->form_validation->set_rules('edit_coach_type', 'Coach Type', 'required|trim');
         $this->form_validation->set_rules('edit_coach_name', 'Coach Name', 'required|trim');
         $this->form_validation->set_rules('edit_designation', 'Designation', 'required|trim');
         $this->form_validation->set_rules('edit_location', 'Location', 'required|trim');
         $this->form_validation->set_rules('edit_description', 'Description', 'required|trim');
         if($this->form_validation->run() == FALSE)
         {
           $data = array('response' =>"error", 'message'=>validation_errors());
         }
         else
         {
           $config['upload_path'] = "./Images/CoachImages/";
           $config['allowed_types'] = 'jpg|jpeg|png';
           $this->load->library('upload', $config);
           if (!$this->upload->do_upload("edit_coach_img")) 
           {
             $data = array('response' => "error", 'message' => $this->upload->display_errors());
           }
           else
           {
             $id = $this->input->post('edit_coach_id');
             if($data = $this->adm->coach_image_entry($id))
             {
                unlink( "./Images/CoachImages/". $data->coach_img);
                $data['coach_img'] = $this->upload->data('file_name');
             }
           }
                
           $data["coach_id"] = $this->input->post('edit_coach_id');
           $data["coach_type"] = $this->input->post('edit_coach_type');
           $data["coach_name"] = $this->input->post('edit_coach_name');
           $data["designation"] = $this->input->post('edit_designation');
           $data["location"] = $this->input->post('edit_location');
           $data["description"] = $this->input->post('edit_description');
           if($this->adm->UpdateCoach($data))
           {
             $data = array('response' =>"success", 'message' =>"Data updated successfully");
           }
           else
           {
             $data = array('response' => "error", 'message' => "failed");
           }
                
        }
        echo json_encode($data);
      }
   }

My Modal Code is here

 public function coach_image_entry($id)
 {
    $this->db->select('*');
    $this->db->from('coach');
    $this->db->where('coach_id', $id);
    $query = $this->db->get();
    if (count($query->result()) > 0) {
        return $query->row();
    }
    else{
        return false;
    }
  }

  public function UpdateCoach($data)
  {
    return $this->db->update('coach', $data , array('coach_id' => $data['coach_id']));
  }

My View file

   <form action="" method="post" id="edit_coach_form">
    <input type="hidden" id="edit_coach_id" value="">
      <div class="form-group">
        <label for="">Coach Image</label>
        <input type="file" class="form-control" id="edit_coach_img">
      </div>
      <div class="form-group">
        <label for="">Coach Type</label>
        <input type="text" id="edit_coach_type" class="form-control">
      </div>
      <div class="form-group">
        <label for="">Coach Name</label>
        <input type="text" id="edit_coach_name" class="form-control">
      </div>
      <div class="form-group">
        <label for="">Designation</label>
        <input type="text" id="edit_designation" class="form-control">
      </div>
      <div class="form-group">
        <label for="">Location</label>
        <input type="text" id="edit_location" class="form-control">
      </div>
      <div class="form-group">
        <label for="">Description</label>
        <input type="text" id="edit_description" class="form-control">
      </div>
     </form>
     </div>
     <div class="modal-footer">
       <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
       <button type="button" class="btn btn-primary" id="update_coach">Update Data</button>
     </div>

Ajax code

   $(document).on("click", "#update_coach", function(e){
    e.preventDefault();
    var edit_coach_id = $("#edit_coach_id").val();
    var edit_coach_img = $("#edit_coach_img")[0].files[0];
    var edit_coach_type = $("#edit_coach_type").val();
    var edit_coach_name = $("#edit_coach_name").val();
    var edit_designation = $("#edit_designation").val();
    var edit_location = $("#edit_location").val();
    var edit_description = $("#edit_description").val();

    if(edit_coach_type == "" || edit_coach_name == "" || edit_designation == "" || edit_location == 
   "" || edit_description == "")
    {
        alert("All fields are required");
    }
    else
    {
        var fd = new FormData();
        fd.append("edit_coach_id", edit_coach_id);
        fd.append("edit_coach_type", edit_coach_type);
        fd.append("edit_coach_name", edit_coach_name);
        fd.append("edit_designation", edit_designation);
        fd.append("edit_location", edit_location);
        fd.append("edit_description", edit_description);
        if ($("#edit_coach_img")[0].files.length > 0) {
            fd.append("edit_coach_img", edit_coach_img);
        }

        $.ajax({
        url: "<?php echo base_url(); ?>UpdateCoach",
        type: "post",
        dataType: "json",
        data:fd,
        processData: false,
        contentType: false,
        success:function(data)
        {
            fetch();
            if(data.response == "success")
            {
                $('#EditCoachModal').modal('hide');
                $("#tbody").DataTable().destroy();
                toastr["success"](data.message)
                toastr.options = {
                    "closeButton": true,
                    "debug": false,
                    "newestOnTop": false,
                    "progressBar": true,
                    "positionClass": "toast-top-right",
                    "preventDuplicates": false,
                    "onclick": null,
                    "showDuration": "300",
                    "hideDuration": "1000",
                    "timeOut": "5000",
                    "extendedTimeOut": "1000",
                    "showEasing": "swing",
                    "hideEasing": "linear",
                    "showMethod": "fadeIn",
                    "hideMethod": "fadeOut"
                }
            }
            else
            {
                $("#tbody").DataTable().destroy();
                toastr["error"](data.message)
                toastr.options = {
                    "closeButton": true,
                    "debug": false,
                    "newestOnTop": false,
                    "progressBar": true,
                    "positionClass": "toast-top-right",
                    "preventDuplicates": false,
                    "onclick": null,
                    "showDuration": "300",
                    "hideDuration": "1000",
                    "timeOut": "5000",
                    "extendedTimeOut": "1000",
                    "showEasing": "swing",
                    "hideEasing": "linear",
                    "showMethod": "fadeIn",
                    "hideMethod": "fadeOut"
                }
            }
        }
    });
    }
  });

I am working on a crud modal which sends some information with a image. I am getting an error if a try to upload a gif image from the database that "response" column is not found in the database but i want a toastr alert like previous toastr alert but i get a database error. I don’t understand why i am getting this error please help me. Thank you

Source: Ask PHP

LEAVE A COMMENT