How to auto refresh list of session array items on submit? <p>I am working on a school comparing website. For this I need a plugin that handles that function. I save session data as school IDs so it can be passed on in the comparing table after choosing the schools.</p> <p>Tasks that I have trouble with:</p> <ol> <li>"Add button" - add post/school ID to session array - $_SESSION['schools']</li> <li>Dashboard at the top - echo $_SESSION['schools'] values (just for user experience list the schools that are currently in the list)</li> <li>when "Add button" is pressed update the dashboard list automaticly. Preferably not the whole page.</li> </ol> <p>My attempt so far:</p> <p>First of all I have I commented PHP form action:</p> <pre><code> &lt;?php session_start(); $schools = array('post_id'); //If form not submitted, display form. if (!isset($_POST['submit_school'])){ //If form submitted, process input. } else { //Retrieve established school array. $schools=($_POST['school']); //Convert user input string into an array. $added=explode(',',$_POST['added']); //Add to the established array. array_splice($schools, count($schools), 0, $added); //This could also be written $schools=array_merge($schools, $added); } $_SESSION['schools'] = $schools; ?&gt; </code></pre> <p>Next up is the form itself:</p> <pre><code> &lt;form method="post" action="http://henrijeret.ee/7788/temp_add_button.php" id="add_school"&gt; &lt;input type="hidden" name="added" value="Value" size="80" /&gt; &lt;?php //Send current school array as hidden form data. foreach ($schools as $s){ echo "&lt;input type=\"hidden\" name=\"school[]\" value=\"$s\" /&gt;\n"; } ?&gt; &lt;input type="submit" name="submit_school" value="Lisa võrdlusesse" /&gt; &lt;/form&gt; </code></pre> <p>And for the dashboard I use:</p> <pre><code> &lt;?php foreach($_SESSION['schools'] as $key =&gt; $value){ // and print out the values echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' &lt;br /&gt;'; } ?&gt; </code></pre> <p>This is just a prototype to get my head wrapper around the task ahead of me...</p> <p><strong>Problems</strong> Something does not feel right.. :P</p> <p>When I submit the form, then the first change is not made. When I press it the second time, then it will update the the list leaving out the very last string. When refreshing then whole page, then the last one pops up</p> <p>I very appriciate the advice on this long topic.. Maby I do not know where to look, but I am a little stuck with searching a solution..</p> <p>Link to my running code <a href="http://henrijeret.ee/7788/" rel="nofollow">http://henrijeret.ee/7788/</a></p>