Good day! There is a form in which the user fills two text input fields and after pressing a button, these two fields fall into a PHP array. The question is how to ensure that when the script is re-running, the values ​​continue to be added to the array, rather than replacing the first value, and can it be implemented in PHP ?

PS Tried through $ _SESSION, did not help.

 $_SESSION['test'][$_POST[key]] = $_POST[invite]; print_r($_SESSION['test']); 
  • 2
    session_start(); Do not forget to insert at the very beginning? - Sergiks
  • sergiks, after adding: Warning: session_start () [function.session-start]: Cannot send session cookie - headers already sent by (output started ...
  • @ ka5itoshka, look at line 1, there you have a conclusion that shouldn’t be before `session_start ();
  • The first line, before the HTML Doctype: <? Php session_start (); ?> - ka5itoshka
  • one
    And the file is not saved in UTF-8 with BOM? - xEdelweiss

1 answer 1

You have been rewriting the value all the time, because it was rewriting. Try this:

 $_SESSION['test'][$_POST[key]][] = $_POST[invite]; 
  • Did not help. Anyway, when the script is run again, the value replaces the first: Array ([test] => Array ([0] => 123)) ka5itoshka
  • The problem is something else. You have a two-dimensional array, and my code creates a three-dimensional. Plus, why test and test2 ? You have a problem somewhere else. - xEdelweiss
  • test - the value that was transferred as a key the first time, test2 - the second. The question was how to run the script twice and save TWO times the key - the value in the array. - ka5itoshka
  • fix session_start(); , everything will be decided - xEdelweiss