我正在尝试创建一个php脚本,该脚本从表单中获取输入值,然后在提交表单时输出建议的行程路线。我将表单方法设置为POST。问题是我得到空白输出。
我不确定问题是我的代码还是POST方法。
class Truck {
// constructor
public function __construct($truck_name, $max_weight) {
$this->truck_name = $truck_name;
$this->max_weight = $max_weight;
}
public function print_truck() {
if (isset($_POST['submit']))
{
$truck_1 = new Truck($truck_name, $max_weight);
$this->truck_name = $_POST['truck_name'];
$this->max_weight = $_POST['max_weight'];
}
echo $this->truck_name;
}
}
class Location {
// constructor
public function __construct($location_name, $location_weight) {
$this->location_name = $location_name;
$this->location_weight = $location_weight;
}
public function trip_1() {
if (isset($_POST['submit'])) {
$location_2 = new Location($location_name, $location_weight);
$this->location_name = $_POST['location_2'];
$this->location_weight = $_POST['package_2'];
$location_3 = new Location($location_name, $location_weight);
$this->location_name = $_POST['location_3'];
$this->location_weight = $_POST['package_3'];
}
echo "Trip #1 \n" . $this->location_2 . ", " . $this->location_3 . "\n";
}
public function trip_2() {
if (isset($_POST['submit'])) {
$location_1 = new Location($location_name, $location_weight);
$this->location_name = $_POST['location_1'];
$this->location_weight = $_POST['package_1'];
}
echo "Trip #2 \n" . $this->location_1;
}
}
# Here's the output HTML:
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Deliveries</title>
</head>
这是预期的结果:
行程1:位置2,位置3
行程2:位置1
子衿沉夜