I wrote simple insert data code but whenever use !empty($author)
it give me this error Fatal error: Call to a member function Create() on boolean
but i remove check for !empty($author)
so then it's work fine. I really don't understand this is giving this error and what mean of it.
Here is my code Comment Class
class Comment extends DatabaseObject{
// Attributes
protected static $TableName = 'comment';
protected static $DBFields = array('id','author','comment','created','photograph_id');
public $id;
public $author;
public $comment;
public $created;
public $photograph_id;
// Create Comment
public static function Make($photograph_id,$author='Anonymous',$body=''){
if(!empty($photograph_id) && !empty($author) && !empty($body)){
$Comment = new Comment();
$Comment->author = $author;
$Comment->comment = $body;
$Comment->photograph_id = (int)$photograph_id;
$Comment->created = date("Y-m-d H:i:s",time());
return $Comment;
}else{
return FALSE;
}
}
// Find Comment Related Picture
public static function CommentOfPicture($photograph_id){
global $db;
$Comment = static::FindByQuery("SELECT * FROM ".static::$TableName." WHERE `photograph_id`='".$db->EscapeValue($photograph_id)."' ORDER BY created ASC");
return $Comment;
}
}
Here is my code of Form Submission
// Comment Submit
if(isset($_POST['submit'])){
$Name = trim($_POST['name']);
$Body = trim($_POST['comment']);
if(!empty($Body) || !empty($Name)){
$Comment = Comment::Make($Photo->id,$Name,$Body);
if($Comment->Create()){
$Session->MSG("Success: Comment is submit, awaiting for approval");
RedirectTo("photo.php?id={$Photo->id}");
}else{
$Session->MSG("Danger: Something is Wrong");
RedirectTo("photo.php?id={$Photo->id}");
}
}else{
$Session->MSG("Danger: Comment is empty");
RedirectTo("photo.php?id={$Photo->id}");
}
}