arrays - Notice: Trying to get property of non-object in C:\xampp\htdocs\xxxx\xxx\blog.php on line 36 1:00 am, January 1 -


i trying build blog site php , mongodb.
built homepage in comment page errors this:

fatal error: call undefined function mongoid() in c:\xampp\htdocs\mydoc\kazma\comment.php on line 11.

here code:

<?php     $id = $_post['article_id'];     try {         $mongodb = new mongo();         $collection = $mongodb->myblogsite->articles;     }catch (mongoconnectionexception $e) {         die('failed connect mongodb '.$e->getmessage());     }     $article = $collection->findone(array('_id' => mongoid($id)));     $comment = array(         'name' => $_post['commenter_name'],         'email' => $_post['commenter_email'],         'comment' => $_post['comment'],         'posted_at' => new mongodate()     );     $collection->update(array('_id' => new mongoid($id)),         array('$push' => array('comments' => $comments)));     header('location: blog.php?id='.$id); ?> 

but after add new line: $article = $collection->findone(array('_id' => mongoid($id)));`

it works fine. whenever try comment throws above error

notice: trying property of non-object in c:\xampp\htdocs\xxx\xxx\blog.php on line 36.

i don't know again. here blog.php code:

<?php  $id = $_get['id']; try{     $connection = new mongo();     $database = $connection->selectdb('myblogsite');     $collection = $database->selectcollection('articles'); } catch(mongoconnectionexception $e){     die("failed connect database ". $e->getmessage()); } $article = $collection->findone(array('_id' => new mongoid($id))); ?>  <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css">     <title>my blog site</title> </head> <body> <div id="contentarea">     <div id="innercontentarea">         <h1><?php echo $article['title']; ?></h1>         <p><?php echo $article['content']; ?></p>         <div id="comment-section">             <?php if (!empty($article['comments'])) : ?>                 <h3>comments</h3>                 <?php foreach ($article['comments'] $comment) :                     echo $comment['name'] . ' says...'; ?>                 <p><?php echo $comment['comment']; ?></p>                 <span>                     ***<?php echo date('g:i a, f j', $comment['posted_at']-> sec); ?>***                 </span><br/><br/><br/>             <?php endforeach;             endif; ?>             <h3>post comment</h3>             <form action="comment.php" method="post">                 <span class="input-label">name</span>                 <input type="text" name="commenter_name" class="comment-input" />                 <br/><br/>                 <span class="input-label">email</span>                 <input  type="text" name="commenter-email" class="comment-input" />                 <br/><br/>                 <textarea name="comment" rows="5"></textarea><br/><br/>                 <input type="hidden" name="article_id" value="<?php echo $article['_id']; ?>" />                 <input type="submit" name="btn_submit" value="save" />             </form>         </div>      </div>  </div> </body> </html> 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -