PHP / Mongo: query won't work if inside a function;

1337Abyssal1337

New Member
The following php throws up this error...\[quote\] Fatal error: Call to a member function findOne() on a non-object in J:\xampplite\htdocs\Produkshunator\home.back.php on line 27\[/quote\]Here's the php...\[code\]<?php/*********************************************** * * Make Connection * *************************************************************/ $conn = new Mongo(); if($_POST['mod'] == "add") { add_data(); }/*********************************************** * * Add data * *************************************************************/ function add_data() { $doc = array("email" => $_POST['email']); $prod = array("productions");/*line 27 -->*/ $category_exists = $conn -> registration -> users -> findOne($doc, $prod); // <--- line 27 if (in_array($_POST['new_title'], $category_exists['productions'])){ $response = array("errormsg" => "That production already exists, please use a unique title."); } else { $newdata = http://stackoverflow.com/questions/3904242/array('$push' => array("productions" => $_POST['new_title'])); $doc = array("email" => $_POST['email']); $conn -> registration -> users -> update($doc, $newdata); $response = array("production" => $_POST['new_title']); } reply($response); }/*************************************************** * * Reply * ***************************************************************/ function reply($response) { echo json_encode($response); }?>\[/code\]... however ... when I comment out the call to add_data() and its function declaration so its all part the 'if' statement it works without a hitch...\[code\] if($_POST['mod'] == "add") {// add_data();// }/*********************************************** * * Add data * *************************************************************/// function add_data() {\[/code\]Is there a workaround, or just something I'm missing. Because otherwise this could get very messy, very fast.
 
Back
Top