У меня есть область, где я обновляю свои продукты, но название моих продуктов должно быть уникальным. Во время обновления я получаю ранее введенную заголовок, даже если я изменил поле описания. Обновление других полей без изменения названия Я хочу сделать, если название меняется, оно должно быть уникальным, чтобы не использовать название предыдущих записей, вы можете мне помочь
контроллер
<?php
public function update ($para1 == "update") {
$options = array();
$this->load->library('form_validation');
$this->form_validation->set_rules("title", "Title", "required|trim|is_unique[product.title]");
$this->form_validation->set_rules("description", "description", "required|trim");
$this->form_validation->set_rules("sale_price", "Price", "required|trim");
$this->form_validation->set_message(
array(
"required" => "<b>{field}</b> This field required",
'is_unique' => 'This %s field must contain a unique value'
)
);
$validate = $this->form_validation->run();
if ($validate) {
if ($_FILES["images"]['name'][0] == '') {
$num_of_imgs = 0;
} else {
$num_of_imgs = count($_FILES["images"]['name']);
}
$num = $this->crud_model->get_type_name_by_id('product', $para2, 'num_of_imgs');
$download = $this->crud_model->get_type_name_by_id('product', $para2, 'download');
$data['title'] = $this->input->post('title');
$data['category'] = $this->input->post('category');
$data['description'] = $this->input->post('description');
$data['sub_category'] = $this->input->post('sub_category');
$data['sale_price'] = $this->input->post('sale_price');
$data['purchase_price'] = $this->input->post('purchase_price');
$data['tax'] = $this->input->post('tax');
$data['discount'] = $this->input->post('discount');
$data['discount_type'] = $this->input->post('discount_type');
$data['tax_type'] = $this->input->post('tax_type');
$data['shipping_cost'] = $this->input->post('shipping_cost');
$data['tag'] = $this->input->post('tag');
$data['color'] = json_encode($this->input->post('color'));
$data['num_of_imgs'] = $num + $num_of_imgs;
$data['front_image'] = 0;
$additional_fields['name'] = json_encode($this->input->post('ad_field_names'));
$additional_fields['value'] = json_encode($this->input->post('ad_field_values'));
$data['additional_fields'] = json_encode($additional_fields);
$data['brand'] = $this->input->post('brand');
$data['unit'] = $this->input->post('unit');
$choice_titles = $this->input->post('op_title');
$choice_types = $this->input->post('op_type');
$choice_no = $this->input->post('op_no');
if(count($choice_titles ) > 0){
foreach ($choice_titles as $i => $row) {
$choice_options = $this->input->post('op_set'.$choice_no[$i]);
$options[] = array(
'no' => $choice_no[$i],
'title' => $choice_titles[$i],
'name' => 'choice_'.$choice_no[$i],
'type' => $choice_types[$i],
'option' => $choice_options
);
}
}
$data['options'] = json_encode($options);
$this->db->where('product_id', $id);
$add = $this->db->update('product', $data);
if ($add) {
$data["type"] = "success";
$data["message"] = "Transaction Successfully";
} else {
$data["type"] = "error";
$data["message"] = "An error occurred during the operation ";
}
} else {
$data["type"] = "error";
$data['message'] = validation_errors();
}
echo json_encode($data);
recache();
}