1

こんにちは、対象人物のインスタンスを読み取り、フォームを使用して個々の詳細を取得し、それをデータベースに入れようとしています。私は自分のコードで人を設定し、データベースに接続していると思います。フォームの情報を処理してデータベースに読み込むときに、正しく取得できません。どんな助けでも大歓迎です!

私のフォーム

    <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」と表示されます

何か案は?ありがとう

4

1 に答える 1

1

あなたは試してみたいかもしれません:

$person = new Person ($i,$firstName, $lastName, $age);

クラスが大文字で定義されている場合は、大文字でも呼び出す必要があります。メソッド/クラス呼び出しの場合と一貫性を保つことは常に良い考えです。Javaのような他の多くの言語では、これは非常に厳密です(ただし、PHPはこのルールについて緩い場合があります)。

于 2012-10-23T18:50:28.713 に答える