title: Unset PHP variables after modal closed
body: <p>Having troubles with a form modal. Basically it works the first time but then every other time it keeps the data from the first.</p>
  
  <p>Basically I have an page (metadata.php) that has a button to open the modal and pass an ID based on some table data.</p>
  
  <p>For some reason the $ID variable is getting stuck and when the user closes the modal and clicks on another edit button it shows the form for the first object. I'm pretty sure it's because i'm not clearing the PHP variables corrects, but the $ID should at least be grabbed every time via the $id = $_REQUEST['id'];.</p>
  
  <p>Any help would be appreciated. </p>
  
  <p>HTML (metadata.php):</p>
  
  <pre><code>&lt;a data-toggle="modal" data-target="#updateModal" class="btn-sm btn-success" href="./update.php?id='.$row['CLUSTERNAME'].'"&gt;Edit&lt;/a&gt;
  </code></pre>
  
  <p>HTML (metadata.php). Note the body is blank because I use it to open update.php:</p>
  
  <pre><code>&lt;div class="modal fade" id="updateModal" tabindex="-1" role="dialog"
                  aria-labelledby="updateModal" aria-hidden="true"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-body"&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>PHP (update.php):</p>
  
  <pre><code>&lt;?php 
  include("../scripts/connect.php");
  include("../config.php");
  
  $id = null;
  
  if ( !empty($_GET['id'])) {
      $id = $_REQUEST['id'];
  
  }
  
  if ( null==$id ) {
      header('Location: ' . $_SERVER['HTTP_REFERER']);
  }
  
  if ( !empty($_POST)) {
      // keep track validation errors
      $datacenterError = null;
      $tierError = null;
  
      // keep track post values
      $datacenter = $_POST['datacenter'];
      $tier = $_POST['tier'];
  
      // validate input
      $valid = true;
      $note = preg_replace('/[^\w%!&amp;, ]/', '', $note); // Removes special chars.
  
      if (empty($datacenter)) {
          $datacenterError = 'Please select a Datacenter';
          $valid = false;
      }
      if (empty($tier)) {
          $tierError = 'Please select a Tier';
          $valid = false;
      }
  
      // update data
      if ($valid) {
  
          $sql = "UPDATE &lt;table&gt; SET DATACENTER='$datacenter', TIER='$tier' WHERE CLUSTERNAME = '$id'";
                      $stmt = sqlsrv_query( $conn, $sql );
                      if( $stmt === false) {
                          die( print_r( sqlsrv_errors(), true) );
                      }
          header('Location: ' . $_SERVER['HTTP_REFERER']);
      }
  } else {
      $sql = "select CLUSTERNAME,VCENTER_NAME,DATACENTER,TIER FROM &lt;table&gt; WHERE CLUSTERNAME = '$id'";
                      $stmt = sqlsrv_query( $conn, $sql );
                      if( $stmt === false) {
                          die( print_r( sqlsrv_errors(), true) );
                      }
      while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
                      $clustername = $row['CLUSTERNAME'];
                      $vcentername = $row['VCENTER_NAME'];
                      $datacenter = $row['DATACENTER'];
                      $tier = $row['TIER'];
                      }
  }
  ?&gt;
  </code></pre>
  
  <p>HTML form (update.php):</p>
  
  <pre><code>&lt;body&gt;
  
  &lt;div class="modal-header"&gt;
  &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
  &lt;h4 class="modal-title" id="myModalLabel"&gt;Update a Cluster&lt;/h4&gt;
  &lt;/div&gt;
  &lt;div class="modal-body"&gt;
  
  &lt;div class="container"&gt;
  &lt;!--Default buttons with dropdown menu--&gt;
  &lt;form class="form-horizontal" action="metadata_update.php?id=&lt;?php echo $id?&gt;" method="post"&gt;
      &lt;div class="col-lg-6"&gt;
  
                  &lt;div class="form-group"&gt;
                    &lt;label class="col-md-4 control-label" for="clustername"&gt;Cluster&lt;/label&gt;  
                    &lt;div class="col-md-6"&gt;
                    &lt;input id="clustername" name="clustername" type="text" value="&lt;?php echo !empty($clustername)?$clustername:'';?&gt;" class="form-control input-md" disabled&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div class="form-group"&gt;
                    &lt;label class="col-md-4 control-label" for="vcentername"&gt;vCenter&lt;/label&gt;  
                    &lt;div class="col-md-6"&gt;
                    &lt;input id="vcentername" name="vcentername" type="text" value="&lt;?php echo !empty($vcentername)?$vcentername:'';?&gt;" class="form-control input-md" disabled&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div class="&lt;?php echo !empty($datacenterError)?'error':'';?&gt; form-group"&gt;
                  &lt;label class="col-md-4 control-label" for="datacenter"&gt;Datacenter&lt;/label&gt;
                  &lt;div class="col-md-6"&gt;
                  &lt;select id="datacenter" name="datacenter" class="form-control" value="&lt;?php echo !empty($datacenter)?$datacenter:'';?&gt;&gt;
                    &lt;option value="test"&gt;test&lt;/option&gt;
                    &lt;option value="test2"&gt;test2&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;?php if (!empty($datacenterError)): ?&gt;
                              &lt;span class="help-block"&gt;&lt;?php echo $datacenterError;?&gt;&lt;/span&gt;
                  &lt;?php endif;?&gt;
                &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="&lt;?php echo !empty($tierError)?'error':'';?&gt; form-group"&gt;
                &lt;label class="col-md-4 control-label" for="tier"&gt;Tier&lt;/label&gt;
                &lt;div class="col-md-6"&gt;
                  &lt;select id="tier" name="tier" class="form-control"&gt;
                    &lt;option value="All"&gt;All&lt;/option&gt;
                    &lt;option value="Empty"&gt;Empty&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;?php if (!empty($tierError)): ?&gt;
                              &lt;span class="help-block"&gt;&lt;?php echo $tierError;?&gt;&lt;/span&gt;
                  &lt;?php endif;?&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                    &lt;div class="form-actions"&gt;
                      &lt;button type="submit" class="btn btn-success"&gt;Update&lt;/button&gt;
                      &lt;button type="button" data-dismiss="modal" class="btn btn-default"&gt;Back&lt;/button&gt;
  
                      &lt;/div&gt;
                  &lt;/form&gt;
                  &lt;/div&gt;
                   &lt;/div&gt; &lt;!-- /container --&gt;
      &lt;/div&gt; &lt;!-- /col --&gt;
    &lt;/div&gt;
  </code></pre>