Ich schrieb einfach einfügen Datencode aber immer !empty($author)
geben Sie mir diesen Fehler Fatal error: Call to a member function Create() on boolean
, aber ich entferne die Prüfung für !empty($author)
so dann ist es in Ordnung. Ich verstehe wirklich nicht, dass das diesen Fehler gibt und was das bedeutet.Schwerwiegender Fehler: Aufruf an eine Member-Funktion Function() on boolean
Hier ist mein Code Kommentar Klasse
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;
}
}
Hier ist mein Code der 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}");
}
}
Überprüfen Sie, ob '$ _POST ['name']' eine leere Zeichenfolge hat. Was übermitteln Sie als "Name"? – vbrmnd
Ich gebe den Autorennamen ein. 'Eingabetext' wenn es leer gelassen wird, sollte es standardmäßig 'Anonymous' darin geschrieben sein, tut es aber nicht. es fügt ein leeres Feld darin ein –