PHP -> Object – Class – Method

Enter your car details below:

Source Code

class Car{

/* public $carname;
public $year;
public $model;*/

public function __construct() {
$this->carname = $_POST[‘carname’];
$this->year = $_POST[‘year’];
$this->model = $_POST[‘model’];

}
function Showall(){
echo $this->year.” “;
echo $this->carname.” “;
echo $this->model.” “;
}

}

}

?>

<form method=”post” action=”6.php”>
<input id=”year” name=”year” placeholder=”Year”></input>
<input id=”carname” name=”carname” placeholder=”Brand”></input>
<input id=”color” name=”model” placeholder=”Model”></input>

<button id=”btn”>go</button>
</form>

<?php echo “<br>Hello, I have a “;
$goodcar= new Car;
$goodcar->Showall();
?>

Comments are closed.