我只是在学习 PHP 课程,所以我在搞乱它。我只是试图从用户那里获取一个值并使用一个类来显示它。但是,当我尝试$_POST
在类中使用变量时,它会显示错误。
这是代码:
<form action="classess.php" method="POST" >
<b>Enter the rate : </b>
<input type="text" name="price" />
<input name="submit" type="submit" value="Click" />
</form>
<?php
class rating
{
public $rate = $_POST['price'];
public function Display()
{
echo $this -> rate;
}
}
$alex = new rating;
$alex ->Display();
?>