我有一个上传表单,通过AJAX上传到MYSQL db。当我提交表单时,除icon
字段外,所有字段都显示在AJAX标题中。我没有遇到问题。完全坚持下去。为什么会这样?
注意:未定义的索引:第46行的response_categories.php中的cat_image
形式
<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");
}