There is an error of "missing update condition" when THINKPHP5 modifies database data.





the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)
first picture code
public function edit () {

$db_01=new DB();
$id_edit=Request::instance()->param("id");
$m=$db_01::table("caipin")->where("id",$id_edit)->select();
$this->assign("m",$m);
return view();

}

second picture code
< form action= "{: url ("Guanli/tz")}" method= "POST" >

    
     {volist name="m" id="vo_edit"}
        <text style="font-size: 15px;" type="" name="id" value="">{$vo_edit.id}                    </text><br>
        <input type="" name="name" value="{$vo_edit.cp_name}"><br>
        <input type="" name="price" value="{$vo_edit.cp_price}"><br>
        <input type="" name="kind" value="{$vo_edit.cp_kind}"><br>
        <input type="submit" name="" value=""><br>
    {/volist}     
</form>

figure 3 Code

public function  tz(){

      if(request()->isPost()){
        $data=[
          "id"=>input("id"),// idIDname
          "cp_name"=>input("name"),//form
          "cp_price"=>input("price"),
           "cp_kind"=>input("kind"),
          ];
         var_dump($data);
              $db=new DB();              
              if($db::table("caipin")->update($data)){        //
                return $this->success("");    //  lst 
            }
            else{
                return $this->error("");
            }


        }

}

what result do you expect? What is the error message actually seen?

Why is the data passed but cannot be updated to the database


update statements need to write conditions, that is, which data should be updated, for example: $db::table ('caipin')-> where (' id',$id)-> update ($data)


this is to prevent you from updating the data of the whole table without adding where. Please make sure that if you really need to do this, you can pass in a where, that is always true, such as

.
  • where
  • whereRaw ('1cm 1')
Menu