Fatal error: Call to a member function fetch_object() on a non-object in C:\wamp\www\NewsToolv1\GetEmAll_Comment.php on line 39
GetEmAll_Comment.php
<?php
$id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_STRING);
$comment = filter_input(INPUT_POST, 'comment', FILTER_SANITIZE_STRING);
$existing_comment = '';
// Check if the comment was set (posted)
if(isset($comment)){
addComment($id, $comment);
echo "record should be added";
} elseif (empty($comment)) {
$existing_comment = checkForComment($id);
}
// Update the database with the new comment
function addComment($id, $comment){
$db = new mysqli('localhost', 'root', '', 'newstoolv1');
$sql = "UPDATE tbl_news SET clmn_comment='".$comment."' WHERE id=".$id;
$db->query($sql);
$db->close();
// Go back to page
$callingPage = $_SERVER['HTTP_REFERER'];
header('location:' . $callingPage);
}
function checkForComment($id){
$db = new mysqli('localhost', 'root', '', 'newstoolv1');
$sql = "SELECT * FROM tbl_news WHERE id=".$id;
$results = $db->query($sql);
$db->close();
$r = '';
while($output_item = $results->fetch_object()){
$r = $output_item->clmn_comment;
}
return $r;
}
?>
<form class="form" method="POST" action="GetEmAll_Comment.php">
<input type="hidden" name="id" value="<?PHP echo $id;?>">
<textarea rows="1" cols="60" name="comment"><?PHP echo $existing_comment;?></textarea>
<input type="submit" value="Submit">
</form>
Edited by ApplicationError, 21 January 2013 - 07:29 PM.











