こんにちは、対象人物のインスタンスを読み取り、フォームを使用して個々の詳細を取得し、それをデータベースに入れようとしています。私は自分のコードで人を設定し、データベースに接続していると思います。フォームの情報を処理してデータベースに読み込むときに、正しく取得できません。どんな助けでも大歓迎です!
私のフォーム
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action="process.php" method="post">
First Name: <input type="text" name="firstName" />
Last Name: <input type="text" name="lastName" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
私はそれを処理しようとしています
<?php
$i = 0;
$firstName = 'firstName';
$lastName = 'lastName';
$age = 'age';
$person = new person ($i,$firstName, $lastName, $age);
$PersonDAO = new PersonDAO();
$dao->insert($person);
?>
私のDAO
class PersonDAO は Person{ protected $link; を拡張します。
public function __construct() {
$host = "localhost";
$database = "test";
$username = "root";
$password = "";
$dsn = "mysql:host=$host;dbname=$database";
$this->link = new PDO($dsn, $username, $password);
$this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function __destruct() {
$this->link = null;
}
public function insert($person){
if (!isset($person) && $person != null){
throw new Exception("Person Required");
}
$sql = "INSERT INTO person(firstName, lastName, age)"
. "VALUES (:firstName, :lastName, :age)";
$params = array(
'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(),
'age' => $person->getAge(),
);
$stmt = $this->link->prepare($sql);
$status = $this->execute($params);
if ($status != true){
$errorInfo = $stmt->errorInfo();
throw new Exception("Could Not Add Person: " . $errorInfo[2]);
}
$id = $this->link->lastInsertId('person');
$person->setId($id);
}
} ?>
私のフォームは正常に表示されますが、送信をクリックすると、「致命的なエラー: Class 'person' not found in /Applications/XAMPP/xamppfiles/htdocs/personProj/process.php on line 6」と表示されます
何か案は?ありがとう