I have one question. So, I have built my PHP application with two text fields (First Name, Last Name) and one submit button (like "Add Contact"). I don't use MySQL. I use array. I want following: The first time when i click submit button I should see the first name and last name of my contact. Second time when i click submit button I should again see the first conact and the new one. Example:
First Click - I see: John Johnson
Second Click - I see: John Johnson (old contact), Peter Peterson (new contact)
Hers is my code:
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Contact {
private $lastname;
private $firstname;
public function getLastname() {
return $this->lastname;
}
public function setLastname($lastname) {
$this->lastname = $lastname;
}
public function getFirstname() {
return $this->firstname;
}
public function setFirstname($firstname) {
$this->firstname = $firstname;
}
}
?>
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Controller {
private $arr;
public static function addContact($person) {
$this->arr[] = $person;
}
public function getArr() {
return $this->arr;
}
public function setArr($arr) {
$this->arr = $arr;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action="" name="form" method="post">
<table>
<tr>
<td>First Name:</td>
<td><input type="text" name="fname" value=""></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lname" value=""></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Add Person"></td>
</tr>
</table>
</form>
<?php
include_once 'Contact.php';
include_once 'Controller.php';
$controller = new Controller();
if (isset($_POST['submit'])) {
$person = new Contact();
$person->setFirstname($_POST['fname']);
$person->setLastname($_POST['lname']);
$controller->addContact($person);
print_r($controller->getArr());
}
?>
</body>
</html>
Thanks