zoukankan      html  css  js  c++  java
  • thinkphp验证要插入数据库

    //持行添加操作
    public function doAdd(){
    //创建验证规则
    $rules=array(
    //array('price','/^[0-9]*$/','无效的价格',1),//必须验证price
    array('price', '/^[0-9]*$/', '无效的价格!', 1, 'regex', 3),
    array('point', '/^[0-9]*$/', '无效的积分!', 1, 'regex', 3),
    );
    //先验证数据库字段
    $r = D("goods")->validate($rules)->create();
    //if($data=M('goods')->create()){
    if($r){
    $r['name']=$r[title];
    $id = M('goods')->add($r); // 写入数据到数据库
    if($id){
    $result=array("status"=>1, "msg"=>'添加成功!');
    $this->ajaxReturn($result,'JSON');
     
    }else{
    $result=array( "status"=>0, "msg"=>'添加失败!');
    $this->ajaxReturn($result,'JSON');
     
    }
    }else{
    $msg=D("goods")->getError();
    //echo $msg;
    $result=array( "status"=>0, "msg"=>$msg);
    $this->ajaxReturn($result,'JSON');
    }
     
    }
  • 相关阅读:
    TensorFlow神经网络集成方案
    过滤节点
    获取子节点
    获取兄弟节点
    获取父节点
    遍历DOM树
    获取修改CSS
    获取修改元素属性
    获取修改value
    获取更新元素文本html()
  • 原文地址:https://www.cnblogs.com/xiaoqiangjun/p/7919275.html
Copyright © 2011-2022 走看看