zoukankan      html  css  js  c++  java
  • 记save函数

        在写商品修改的代码的时候,我使用到了create()函数,也使用到了save函数。但是我从表单接受过来的数据,在添加语句的时候都没成功。代码如下

     function upd($goods_id){
             $goods=D("Goods");
             if(!empty($_POST))
             {
                 show($_POST);
                 $goods->create();
                 $result=$goods->where("goods_id=".$goods_id)->save();
                 if($result){
                     $this->redirect("Goods/showlist");
                 }
             }
             else{
              $goodsinfo=$goods->select();
             //show($goodsinfo);
              $this->assign("goodsinfo",$goodsinfo);     
              $this->display();
             }
     
        }

    说出表单接受数据为

    对比数据库

    对比可以发现,表单的数据没主键。我查看手册save的用法

    所以使用save的时候一定要有主键。后来我添加了where()。执行成功了,代码如下

    function upd($goods_id){
             $goods=D("Goods");
             if(!empty($_POST))
             {
                 show($_POST);
                 $goods->create();
                 $result=$goods->where("goods_id=".$goods_id)->save();
                 if($result){
                     $this->redirect("Goods/showlist");
                 }
             }
             else{
              $goodsinfo=$goods->where("goods_id=".$goods_id)->select();
             //show($goodsinfo);
              $this->assign("goodsinfo",$goodsinfo);     
              $this->display();
             }
     
        }
  • 相关阅读:
    python pickle模块
    python struct模块
    python threading模块
    python queue模块
    python3 requests模块 基本操作
    python json模块
    C语言回调函数
    工厂方法模式
    git fetch, git pull 以及 FETCH_HEAD
    git删除远程文件夹或文件的方法
  • 原文地址:https://www.cnblogs.com/zhaoshunjie/p/4648291.html
Copyright © 2011-2022 走看看