1

我在将所有 POST 字段保存到 MongoDB 时遇到了一个小问题

function savedata($data){
        $collection = $this->db->retail_logs;
        $this->data = json_decode($data);


        try {
        $collection->update(
            array("tradingname"=>$this->data['tradingname']),
            $this->data, "date"=> date("d.m.Y"), "time"=>date("H:i:s"),"whochanged"=>$_COOKIE['CRMUIDkey']), // new lead document to insert
            array("upsert" => true, "safe" => true)
            );
        } catch (Exception $e) {
            // Something went wrong .. 
        }
    }

对于某些原因,包含 $_POST 的 $this->data 不想去那里我得到这个错误

Warning: json_decode() expects parameter 1 to be string, array given in /home/crmvip/public_html/system/db/mongo.php on line 294

Warning: MongoCollection::update() expects at most 3 parameters, 4 given in /home/crmvip/public_html/system/db/mongo.php on line 302

它会发送应有的 POST 信息tradingname=monkey&street=abc

4

1 回答 1

1

json_decode用于解码 JSON。

如果您只想保存data通过 POST 请求收到的值:

   $this->data = $_POST['data'];
于 2012-07-26T05:20:07.767 回答