benqus benqus - 9 months ago 48
PHP Question

What might be wrong with this MongoDB update $set query via PHP?

I am a little stuck with an updating on a collection.

So, I have this query:

array("_id" => new MongoId($_POST["id"])),
array("$set" => array(
"contentType" => htmlspecialchars(strip_tags(trim($_POST["type"]))),
"contentTitle" => htmlspecialchars(strip_tags(trim($_POST["title"]))),
"contentBody" => htmlspecialchars(strip_tags(trim($_POST["content"])))

Please don't bother with the way of validating the $_POST, it's only a test, but it doesn't work. The collection is ok, I have checked that. It doesn't do anything, and when I insert

it gives me no errors at all.

Answer Source

Okay, I have got the solution for the moment.

$r = $coll->findOne(
                "_id" => new MongoId($_POST["id"])
        $r["contentType"] = htmlspecialchars(strip_tags(trim($_POST["type"])));
        $r["contentTitle"] = htmlspecialchars(strip_tags(trim($_POST["title"])));
        $r["contentBody"] = htmlspecialchars(strip_tags(trim($_POST["content"])));

So this one works fine. However I would very much like to find out the previous thingy... =P If anyone knows why it isn't working feel free to answer! =]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download