Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:18:36+00:00 2026-06-12T09:18:36+00:00

I have one question. So, I have built my PHP application with two text

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:18:36+00:00Added an answer on June 12, 2026 at 9:18 am

    As mentioned earlier you can use sessions as a storage, but it only lasts until session timeouts (defaults to 30 minutes).

    <?php
    session_start();
     if (!isset($_SESSION['names']) || $_SERVER['REQUEST_METHOD'] == 'GET')
        $_SESSION['names'] = array();
    if (!empty($_POST)) {
      $_SESSION['names'][] = $_POST['name'];
    } 
    ?>
    
    <?php foreach($_SESSION['names'] as $name): ?>
      <?php echo $name ?>
    <?php endforeach; ?>
    <form method="post">
      <input type="text" name="name" />
      <input type="submit" value="Add" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one question; In my ASP.NET MVC web application have to do certain
I want to implement this view But I have one question: The text which
i have one question about jquery ajax().. I created a table grid and there
I have one question about searching and counting files in directories and subdirectories. I
I have one question about Yii framework, and I need your help. Basicly, I
I have one question, I was trying to find more information on the internet
I have one question, in my company we are using Toxicity report to measure
I have one question. I am using Apache CXF framework to generate model classes
I am learning JPA and have one question: In which situations we need more
Edit 4/4/12 I STILL HAVE ONE QUESTION: I solved my issue but it adds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.