我可以在下一个函数中获取$ _POST变量一次,但是当重复该函数或转到下一个函数时,变量是不可访问的。我正在使用PHP类和多个函数。我已经搜索过,并且没有找到解决方案。也许我错过了一些简单的事情。我是新手使用PHP中的类,还有$ _POST变量。我不清楚为什么他们在某些功能中无法访问。提前谢谢。
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$MainPage = new MainPage();
$MainPage->showMainPage();
class MainPage
{
function __construct()
{
}
public function showMainPage()
{
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
echo "<!DOCTYPE html>";
echo "<html>";
echo "<head>";
echo "<meta charset=\"utf-8\">";
echo " </head>";
echo "<body>";
$showmainoptions = 0;
if (isset($_GET['showmainoptions']))
{
$showmainoptions = $_GET['showmainoptions'];
}
$showFinOptions = 0;
if (isset($_GET['showfinoptions']))
{
$showFinOptions = $_GET['showfinoptions'];
}
$showInspectionList = 0;
if (isset($_GET['showinspectionlist']))
{
$showInspectionList = $_GET['showinspectionlist'];
}
if($showmainoptions)
{
$this->showMainOptions();
}
if($showFinOptions)
{
$this->showFinOptions();
}
if($showInspectionList)
{
$this->showInspectionList();
}
$this->showFooterHTML();
return;
}
public function showMainOptions()
{
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
echo "Select Main Options<br>";
echo "<form name=\"submitMainOptions\" id=\"submitMainOptions\" method=\"post\" action=\"mainpage.php?showmainoptions=0&showfinoptions=1&showinspectionlist=0&addnewinspection=0\">";
echo "<label><font size=4px>Wharehouse</font></label> ";
echo "<select id=\"house\" name=\"house\" required>";
echo "<option value=\"\" selected></option>";
echo "<option value=\"CYP\">Cypress</option>";
echo "<option value=\"FAY\">Fayetville</option>";
echo "<option value=\"FUR\">Furnace</option>";
echo "</select>";
echo "<br>";
echo "<label><font size=4px>Fin Type</font></label> ";
echo "<select id=\"fintype\" name=\"fintype\" required>";
echo "<option value=\"\" selected></option>";
echo "<option value=\"Copper\">Copper</option>";
echo "<option value=\"Aluminum\">Aluminum</option>";
echo "</select>";
echo "<br>";
echo "<label><font size=4px>Shift</font></label> ";
echo "<select id=\"shift\" name=\"shift\" required>";
echo "<option value=\"\" selected></option>";
echo "<option value=\"1\">Shift 1</option>";
echo "<option value=\"2\">Shift 2</option>";
echo "<option value=\"3\">Shift 3</option>";
echo "</select>";
echo "<br>";
echo "<button type=\"submit\" class=\"btn btn-primary btn-block btn-flat\">Continue</button></a>";
echo "</form>";
}
public function showFinOptions()
{
$house = $_POST['house'];
echo $house."<br>";
echo "Select Fin Options<br>";
echo "<form name=\"submitFinSelection\" id=\"submitFinSelection\" method=\"post\" action=\"mainpage.php?showmainoptions=0&showfinoptions=0&showinspectionlist=1&addnewinspection=0\">";
echo "<label><font size=4px>Part No</font></label> ";
echo "<select id=\"partno\" name=\"partno\" required>";
echo "<option value=\"\" selected></option>";
echo "<option value=\"partno1\">partno 1</option>";
echo "<option value=\"partno2\">partno 2</option>";
echo "<option value=\"partno3\">partno 3</option>";
echo "</select>";
echo "<br>";
echo "<label><font size=4px>Fin Size</font></label> ";
echo "<select id=\"finsize\" name=\"finsize\" required>";
echo "<option value=\"\" selected></option>";
echo "<option value=\"5mm\">5mm</option>";
echo "<option value=\"7mm\">7mm</option>";
echo "</select>";
echo "<br>";
echo "<label><font size=4px>Press No</font></label> ";
echo "<select id=\"pressno\" name=\"pressno\" required>";
echo "<option value=\"\" selected></option>";
echo "<option value=\"CF016\">CF016</option>";
echo "<option value=\"CF018\">CF018</option>";
echo "<option value=\"CF020\">CF020</option>";
echo "</select>";
echo "<br>";
echo "<button type=\"submit\" class=\"btn btn-primary btn-block btn-flat\">Continue</button></a>";
echo "</form>";
}
public function showInspectionList()
{
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$house = $_POST['house'];
echo $house."<br>";
$pressno = $_POST['pressno'];
echo $pressno."<br>";
}
public function showFooterHTML()
{
echo " </body>";
echo "</html>";
return;
}
}
?>