我已经在html中创建了一个表单,它使用php中的post方法将所有信息打印出来供用户使用,但它看起来像我的表单有问题。它不打印用户输入的详细信息,我试图填充,然后按提交创建类配置文件的对象,将用户的所有信息分配给对象并在浏览器上打印出来,但没有任何内容出现在浏览器上。表单不打印出详细信息
我也试图回应像getFirstName这样的方法,但它同样没有出现,任何人都可以帮助我找出最新的代码问题,我该如何解决它。
请注意,我已经包含三个不同的文件,一个是html表单,另一个是passingdata.php,它将获取用户输入的所有信息,第三个文件是用于传递数据以创建一个对象并为其提供所有需要的信息以创建该类的对象。
最后,我已经调用了哪些应打印出用户输入的所有信息的方法printDeatils
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php echo 'Student Deatils'; ?></title>
</head>
<body>
<p>Please enter your Details:</p>
<div>
<form name="student" method="post" action="passingdata.php">
<div>
<label>First name:</label> <input type ="text" name="first_name">
<label>Last name</label> <input type ="text" name="last_name">
<br></br>
<label>International student</label> <input type="checkbox" name="international">
<br></br>
<fieldset>
<legend>Course</legend>
<label>CS <input type="radio" name="course" value="CS"></label>
<label>SE <input type="radio" name="course" value="SE"></label>
<label>MIT <input type="radio" name="course" value="MIT"></label>
</fieldset>
<br></br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Resit" value="Reset">
</div>
</form>
</div>
<?php
?>
</body>
</html>
的传递数据文件:
类简介:
<?php
class Profile {
private $_firstName, $_lastName, $_international, $_course;
function __contruct ($firstName, $lastName, $course, $international) {
$this->_firstName = $firstName;
$this->_lastName = $lastName;
$this->_course = $course;
$this->_international = $international;
}
public function setFirstName($firstName)
{
$this->_firstName = $firstName;
}
public function setLastName($lastName)
{
$this->_lastName = $lastName;
}
public function setInternational($inter)
{
$this->_international = $inter;
}
public function setCourse($course)
{
$this->_course = $course;
}
public function getFirstName()
{
return $this->_firstName;
}
public function getLastName()
{
return $this->_lastName;
}
public function getInternational()
{
return $this->_international;
}
public function getCourse()
{
return $this->_course;
}
public function printDtails()
{
echo "$_firstName";
}
}
?>
您需要回显'$ this - > _ firstName' - 您在setters和getters中正确使用它,但不能在打印功能中使用它。 – andrewsi
$ this - > _ firstName不是$ _firstName – 2014-01-07 19:55:55
我试过了,但它不起作用 – user3170512