I'm new to PHP and have a problem. I have a navbar on the side of a homepage that displays 4 links. I'm supposed to write a method setWhichPage in a child class that will access a CGI parameter named 'whichpage' from a parent class and use it to determine which of the 4 linked pages will display in the main section of the homepage, using another method called getMainFunction. The navbar was created with the methods getLeftNavBar and createNavbarArray, which exist in the child class (called TravelAgent), but get their variables from the parent class (called Company). The method setWhichPage is supposed to be in this child class also. I'm supposed to use the value $_GET or $_REQUEST array to set the value in the property $whichpage. The acceptable values for the $whichpage property should match the getLeftNavBar method. The methods getLeftNavBar and setWhichPage work together so that when the user clicks on a link in the navbar the URL they are supposed to create these links:
http://amazingadventures.000webhostapp.com/?whichpage=home
http://amazingadventures.000webhostapp.com/?whichpage=sales
http://amazingadventures.000webhostapp.com/?whichpage=support
http://amazingadventures.000webhostapp.com/?whichpage=contact
Where I'm having trouble is when I try to get setWhichPage to set the variable $whichpage to one of the four values in the links, I get this error message:
Notice: Undefined index: whichpage in /storage/ssd1/873/8888873/public_html/index.php
Can you tell me what I'm doing wrong? Thanks in advance for any help. Here's the relevant code:
<?php
class Company { //start of parent class Company
protected $company_name;
protected $company_address;
protected $company_url;
protected $company_email;
protected $whichpage;
public function __construct(){
$this->company_name = "Amazing Adventures Travel";
$this->company_address = "13999 Turtle Way, Los Angeles, California, 90001";
$this->company_url = "http://amazingadventures.000webhostapp.com/";
$this->company_email = "email.edu";
$this->whichpage = "home";
}
//other methods...
} //end of parent class Company
class TravelAgent extends Company { //start of child class TravelAgent
var $navbar_array;
function create_navbar_array() {
$mainurl = $this->company_url;
$this->navbar_array = array("Home Page"=>"$mainurl?whichpage=home", "Sales"=>"$mainurl?whichpage=sales",
"Support" => "$mainurl?whichpage=support", "Contacts" => "$mainurl?whichpage=contact");
}
function getLeftNavBar() {
echo "<table border=1, td width=100, height = 40><tr>";
foreach($this->navbar_array as $x => $x_value) {
echo '<tr><td><a href="' . $x_value . '">'. $x ."</a></td></tr>";
echo "<br>";
}
echo "</tr></table>";
}
function setWhichPage(){
$whichpage = $_GET['whichpage'];
}
function getMainSection() {
echo "The ".$whichpage." page";
}
}
//end of child class TravelAgent
$travelobject = new TravelAgent(); //object creation
$travelobject->getHeader(); //function calls
$travelobject->create_navbar_array();
$travelobject->getLeftNavBar();
$travelobject->setWhichPage();
$travelobject->getFooter();
?>
<table style='width:100%' border='1'> //HTML
<tr>
<td style='width:15%'>Left Navigation Bar</td>
<td> getMainSection()</td> //function call
</tr>
</table>