我創建了一個php人類和一個非常基本的表單。表單是將數據輸出到另一個頁面。這是一個縮小的版本,它沒有包含所有的編碼,但我認爲我有這個編碼。我無法弄清楚它爲什麼不起作用。它不能是任何大事,我不認爲我錯過了任何步驟。請注意我的代碼如下:PHP - 類對象錯誤
我沒有得到任何錯誤...該數據被鍵入表單不是呈現到我的proceslogin.php頁面。
這是我的表格。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>
<div>
<form id="login" method="post" action="proceslogin.php">
<label for="firstname"> First Name: </label>
<input type="text" id="firstname" name="firstname" maxlength="100" tabindex="1" />
<label for="lastname"> Last Name: </label>
<input type="text" id="lastname" name="lastname" maxlength="100" tabindex="2" />
<input type="submit" id="submit" name="submit" value="Retrieve Full Name"/>
</form>
</div>
<body>
</body>
</html>
這是我的課
<?php
//Person Class
class Person{
//attributes for the first and last name of the class
private $firstname;
private $lastname;
/*Constructs the function*/
public function __construct(){
}
/*Destroys the function*/
public function __destruct(){
}
/*Get function*/
public function __get($name) {
return $this->$name;
}
/*Use the set function*/
public function __set($name, $value) {
$this->$name=$value;
}
/*Whis is what retrieves the values from memmory*/
public function retrieve_full_name() {
$fullname = $this->firstname . ' ' . $this->lastname;
return $fullname;
}
} //End of class
?>
這是網頁類對象是在渲染。
<?php
require_once('websiteconfig.inc.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Process Login</title>
</head>
<div class="container" id="shadow">
<div>
<?php
//include for the header
require_once(ABSOLUTE_PATH . 'header.inc.php');
//This is the inlcude for the class files
require_once('class/person.class.php');
//Instantiate person class
$person = new Person();
//sets atributes for both firs and last names
$person->firstname = $_POST['$firstname'];
$person->firstname = $_POST['$lastname'];
?>
</div>
<p>
<?
echo 'Your full name is ' . $person->retrieve_full_name() . ' .' ;
?>
</p>
<div>
</hr>
</div><!--End of Body-->
<?php
//include for the footer
require_once(ABSOLUTE_PATH . 'footer.inc.php');
?>
</div><!--end of header-->
<body>
</body>
</html>
你會得到什麼錯誤? (在你發佈的例子中,你沒有設置姓氏,但名字兩次) – scibuff 2012-03-04 02:17:07