生成带哈希的插入语句

时间:2017-03-14 01:46:47

标签: php codeigniter-3

我想将我的id hashed添加到同一个插入的哈希列中。关于添加一个隐藏的东西我很兴奋,但我认为不行,但是这个工作不需要触发器,如何在没有添加新按钮的情况下在php中执行此操作?

将根据id生成查询。

其中md5(id)然后列中的isnert,我怎么能把所有在一起= 表 id哈希 1 27669f3f141da48bfe5e6b7aa37c38f9

添加控制器

public function addProduct(){
        $descripcion = $this->input->post('description');
        $cost_price =  $this->input->post('cost_price');
        $selling_price = $this->input->post('selling_price');
        $wprice = $this->input->post('wprice');
        $min_stock = $this->input->post('min_stock');
        $stock = $this->input->post('stock');
        $max_stock = $this->input->post('max_stock');
        $data = array(
            'hash' => $this->hash_id($descripcion),
            'descripcion' => $descripcion,
            'precio_compra' => $cost_price,
            'precio_venta' => $selling_price,
            'precio_mayoreo' => $wprice,
            'existencia_minima' => $min_stock,
            'existencia' => $stock,
            'existencia_maxima' => $max_stock
        );

        if ($data['existencia'] > $data['existencia_minima']) {
            $this->json(array('min_stock' => 'el stock no puede ser mayor al min'));
        }elseif ($data['existencia_maxima'] < $data['existencia']) {
            $this->json(array('max_stock' => 'el stock no puede ser mayor al max'));
        }else{
            if (!$this->products->isExistsProduct($data)) {
                $this->products->addProduct($data);
                $this->json(array('msg' => 'successfully added'));
            }else{
                $this->json(array('duplicate' => 'product already exists'));
            }
        }
    }

模型

public function addProduct($data){
        $this->db->insert('storelte_articulos',$data);
    }

表格

<form id="update_product">
   <div class="row">
   <div class="form-group">
   <div class="col-xs-12">
      <label for="description">Name: </label>
      <input type="text" class="form-control" id="description" name="description" title="product description" required>
      <div>
      </div>
   </div>
   <div class="row">
      <div class="form-group">
         <div class="col-xs-8 col-sm-6">
            <label for="cost_price">Cost Price: </label>
            <div class="input-group"> <span class="input-group-addon">$</span>
               <input type="text" class="form-control input-group-lg reg_name" id="cost_price" name="cost_price" title="cost_price"  placeholder="Last name" required>
            </div>
         </div>
         <div class="col-xs-8 col-sm-6">
            <label for="selling_price">Selling price: </label>
            <input type="text" class="form-control input-group-lg reg_name" id="selling_price" name="selling_price" title="selling_price" placeholder="Last name" required>
         </div>
      </div>
   </div>
   <div class="row">
      <div class="form-group">
         <div class="col-xs-8 col-sm-6">
            <label for="wprice">Wholeprice: </label>
            <input type="text" class="form-control" id="wprice" name="wprice" title="wprice" required>
         </div>
         <div class="col-xs-8 col-sm-6">
            <label for="min_stock">Min stock: </label>
            <input type="text" class="form-control" id="min_stock" name="min_stock" title="min_stock" required>
         </div>
      </div>
   </div>
   <div class="row">
      <div class="form-group">
         <div class="col-xs-8 col-sm-6">
            <label for="stock">Stock: </label>
            <input type="text" class="form-control" id="stock" name="stock" title="stock" required>
         </div>
         <div class="col-xs-8 col-sm-6">
            <label for="max_stock">Max stock: </label>
            <input type="text" class="form-control" id="max_stock" name="max_stock" title="max_stock" required>
         </div>
      </div>
   </div>
</form>

1 个答案:

答案 0 :(得分:0)

使用此方法获取插入的ID $这 - &GT; DB-&GT; INSERT_ID() 并更新了数据(哈希)