0
사용자가 세 개의 매개 변수 너비와 높이를 입력하고 Tringle 또는 Rectangle을 입력해야하는 PHP 파일이 있습니다. PHP의 첫 번째 코드에서 폭과 높이 매개 변수를 읽고 라인 코드의 끝 부분에서 php를 시도합니다. Tringle 또는 rectangle 매개 변수의 모양을 읽고이 매개 변수에 따라 면적을 계산합니다. 임의의 healp에 대한 Thx.게시물을 사용하여 PHP에서 폼에 매개 변수를 성공적으로 전달할 수 없습니다
<h2>OOP Class Demo</h2>
<p>
Please enter two numbers to calculated the area of rectangle or tringle and press submit...
<p>
<form method="post" action="demo.php">
<br>width.1 <input type=text name=num_a>
<br>height.2 <input type=text name=num_b>
<br><input type="radio" name="shape" value="Rectangle" /> Rectangle
<br><input type="radio" name="shape" value="Tringle" /> Tringle
<br><input type=submit>
</form>
<?php
echo("<br>");
if(isset($_POST['submit']))
{echo "THERE is submit.!";
Class Rectangle {
//Declare the attributes:
public $width = $_POST['width'];
public $height = $_POST['height'];
protected static $formula = 0;
//Method to set the dimensions.
Function create_formula() {
self :: $formula = $this->width * $this->height;
}
//Method to set the dimensions.
Function set_size($w = 0, $h = 0) {
$this->width = $w;
$this->height = $h;
$this->create_formula();
}
//Method to calculate and return the area.
function get_area() {
return (self::$formula);
}
}
Class Triangle extends Rectangle{
Function create_formula() {
self :: $formula = ($this->width * $this->height)/2;
}
}
if (!$_POST['shape']){echo('your choice is: '.$_POST['shape']);}
// create object of rectangle and calculate it is area
$rect = new Rectangle();
echo ($rect->get_area()."<br />");
// create object of tringle and calculate it is area by extends
$tri = new Triangle();
echo $tri->get_area();
}
?>
을해야한다 \t 선언 \t - 구문 오류, 예기치 않은 '$ _POST'감사합니다. –