title: How to update a session variable
body: <p>I am creating a multi-step form with Ajax and would like to change text displayed based on the value of a form field. I thought that a good way to do this would be with a session variable. How do I tell the session to update with the new field value? Currently, the session only seems to store the initial value, but not any updates to it. So if a user enters "John" as the first name and then later goes back and changes it to "Frank," "John" is the name stored.</p>
  
  <pre><code>if (!isset($_SESSION)) {
  session_start();
  $_SESSION['formStarted'] = true;
  $_SESSION['timestamp'] = date("M d Y H:i:s");
  $_SESSION[$key] = $value;
  
  &lt;p&gt;Your name begins with the letter &lt;?php if ($_SESSION['name'] =='Frank') 
    {echo 'F';}?&gt;&lt;p&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>$("#form").validate({
     //...
     submitHandler: function(form) {
  
     //... 
     $(form).ajaxSubmit({               
       type: "POST",
       data: {
         name : $('#name').val(),
  //...
       },
       dataType: 'json',
       url: '../ajaxtest.php',
       error: function() {alert("There was an error processing this page.");},
       success: 
         function(data) {
           $('#output1').html(data.message.join(' ')).show(500);
           $('#ouput1').append(data);
  //...
  </code></pre>
  
  <p>ajaxtest.php:</p>
  
  <pre><code>session_start();
  
  $expected = array( 
  'name'=&gt;'string', 
  //...
  );
  
  //...
  
  $return['message']=array();
  if(!empty($_POST['name'])){
     $return['message'][] = '' . htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
     } 
  //...
  echo json_encode($return);
  </code></pre>