1

I have an upload form which uploads through AJAX to MYSQL db. When i submit my form, all the fields are being displayed in AJAX headers except icon field. I am not getting the problem. Totally stuck with it. Why is it so?

Notice: Undefined index: cat_image in response_categories.php on line 46

form

 <div class="modal-body">
     <form method="post" id="frm_add" enctype="multipart/form-data">
     <input type="hidden" value="add" name="action" id="action">
     <div class="form-group">
      <label for="name" class="control-label">Name:</label>
      <input type="text" class="form-control" id="cat_name" name="cat_name"/>
      </div>
      <div class="form-group">
      <label for="salary" class="control-label">Icon:</label>
       <input type="file" name="cat_image" id="cat_image"/>
       </div>
       <label>Type:</label>
       <input type="radio" name="cat_type" value="1" /> Special
       <input  type="radio" name="cat_type" value="0"/> Ordinary
       <label>Switch:</label>
       <input type="radio" name="cat_switch" value="1"/>  On
       <input  type="radio" name="cat_switch" value="0"/> Off
       </div>

AJAX

function ajaxAction(action) {
            data = $("#frm_add").serializeArray();
            $.ajax({
                type: "POST",
                url: "response_categories.php",
                data: data,
                dataType: "json",
                success: function(response)
                {
                    $('#'+action+'_model').modal('hide');
                    $("#categories_grid").bootgrid('reload');
                }
            });
        }

response_categories.php

function insertCategories($params) {
        $data = array();
        // print_R($params);
        // die;
        $img=$_POST['cat_image']['name'];// line 46
        $temp_name=$_POST["cat_image"]["tmp_name"];
        $sql = "INSERT INTO `categories` (cat_name,cat_image, cat_type, cat_switch) VALUES('" . $params["cat_name"] . "','" . $temp_name . "', '" . $params["cat_type"] . "','" . $params["cat_switch"] . "');  ";

        echo $result = mysqli_query($this->conn, $sql) or die("error to insert Categories data");

    }
tabia
  • 631
  • 2
  • 10
  • 33

0 Answers0