I have the following problem. I created a .php file that creates(extends) two new pages. In the first page there is a button called submit which after click on it send me to the next page called editname. When I made click on the button (edit)of the second page, it send me to the third page called recorndname. In the third page, there are two buttons called update and delete which send me to the second page. But, actually it is working as it should. Here is part of my code.
//here is my main class
class main {
public function __construct() {
$page_request = 'homepage';
if(isset($_REQUEST['page'])) {
$page_request = $_REQUEST['page'];
}
$page = new $page_request;
if($_SERVER['REQUEST_METHOD'] == 'GET') {
$page->get();
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST'){
$page->post();
} else{
$page->delete();
}
}
}
Here is my page class. In this part seems neither one of the functions are called.
//Page class
class page {
public function get() {
echo 'I am a get method page';
}
public function post() {
echo 'I am a post method';
$user=new users();
//$user->addUser($_POST["firstname"],$_POST["lastname"],$_POST["email"]);
if($_POST['botton'] == 'Submit'){
$user->addUser($_POST["firstname"],$_POST["lastname"],$_POST["email"]);
} else if($_POST['botton'] == 'Update'){
$user->update($_POST["email"],$_POST["firstname"],$_POST["lastname"]);
} else if($_POST['botton'] == 'Delete'){
$user->deleteUser($_POST["email"]);
}
}
public function delete(){
echo 'I am a delete method';
}
}
Here are my extended pages.
//Page classes
class homepage extends page {
public function get() {
echo 'homepage';
echo'<form action="projectBackup.php?page=editname" method="post">
First name:<br>
<input type="text" name="firstname" value="">
<br>
Last name:<br>
<input type="text" name="lastname" value="">
<br>
Email Address:<br>
<input type="text" name="email" value="">
<br><br>
<input type="submit" name="button" value="Submit">
</form>';
}
}
class editname extends page {
public function post(){
echo 'editname';
$users=new users();
$userlist=$users->listUsers();
echo '<table><tr><th>First Name</th><th>Last Name</th><th>Email Address</th></tr>';
foreach($userlist as $Kuser=>$user){
echo '<tr><td>'.$user['fname'].'</td><td>'.$user['lname'].'</td><td>'.$Kuser.'</td><td>';
echo '<form action="projectBackup.php?page=recordname" method="get">
<input type="hidden" name="email" value="$Kuser">
<input type="submit" value="Edit"></form>';
}
echo '</table>';
}
}
class recordname extends page {
public function get() {
echo 'recordname';
$users=new users();
$userlist=$users->listUsers();
echo'<form action="projectBackup.php?page=editname" method="post">
First name:<br>
<input type="text" name="firstname" value="$userlist[$_GET["email"]["fname"]">
<br>
Last name:<br>
<input type="text name="lastname" value="$userlist[$_GET["email"]["lname"]">
<br>
Email Address:<br>
<input type="text" name="email" value="$_GET["email"]">
<br><br>
<input type="submit" name="button" value="Update">
<input type="submit" name="button" value="Delete">
</form>';
}
}
Can someone help me with this? Thank you in advance.
0 comments:
Post a Comment