嘿,我是PHP新手,但我知道Java的基本知識,並瞭解Java中的面向對象,但我試圖理解如何使它通過面向對象與HTML交織。爲什麼下面的代碼不會回傳消息?謝謝。我的PHP OOP在哪裏錯了?
<?php
class SubmitPost {
public function __construct() {
$Db = new PDO('mysql:host=localhost;dbname=Comment', 'root', '');
}
public function Comment($Post, $Time, $Title) {
$Post = strip_tags($_POST['Post']);
$Time = time();
$Title = strip_tags($_POST['Title']);
$Messages = array('success' => 'Your comment has been added.', 'error' => 'There was a problem adding your comment.');
if(isset($Post, $Title)) {
return $Messages['success'];
} else {
return $Messages['error'];
}
}
}
$New = new SubmitPost;
var_dump($New);
?>
<html>
<head>
</head>
<body>
<form action="OO.php" method="POST">
<input type="text" name="Title" placeholder="Your Title"><br />
<textarea placeholder="Your Comment" name="Post"></textarea><br />
<input type="submit" value="Comment">
</form>
</body>
</html>
你是不是執行'Comment'功能,只需構造。而且它似乎並不需要參數。 – elclanrs
檢查請求類型是否發佈,然後運行'$ New-> Comment()'。 (無論如何,所有的參數都不會被使用,它們被設置在函數中。) –
沒有任何屬性的類? –