2 Replies - 490 Views - Last Post: 13 July 2013 - 06:14 AM Rate Topic: -----

#1 Astro52a9  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 24-March 13

Add to Array from a form

Posted 13 July 2013 - 04:04 AM

I have this simple text code that i want to get the input from the user and add it to my array but it only holds one and keep replacing it
I am a newbie so


$name_array = array();

array_push ($name_array,$_GET['name']);



<form action="formtest.php" method="GET">
	Name<input type="text" name="name"><br>
	<input type="submit" value="Submit"><br>


Is This A Good Question/Topic? 0
  • +

Replies To: Add to Array from a form

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3490
  • View blog
  • Posts: 12,441
  • Joined: 08-August 08

Re: Add to Array from a form

Posted 13 July 2013 - 04:40 AM

Your form only submits one element. How many do you hope to add?
HTML is processed on the browser and PHP is processed on the server. Two different computers and at two different times. Putting them in the same file dos not change this fact.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • There's no such thing as the Dog Poo Fairy
  • member icon

Reputation: 5794
  • View blog
  • Posts: 22,948
  • Joined: 12-December 12

Re: Add to Array from a form

Posted 13 July 2013 - 06:14 AM

.. each time your form is submitted, the page is re-loaded. This runs your script entirely from scratch, so the array $name_array is re-created each time.

If you want to store any previous values you'll need to persist them by saving them in a database. Or, if appropriate, in a cookie or session-data (or some other technology).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1