title: Comboboxes not updating
body: <p>I have two php pages, <strong>admin_bkp.php</strong> and <strong>db_submit.php</strong>.</p>
  
  <p>The <strong>admin_bkp.php</strong> gives a user a table that let's the user set permissions to employees and save the permissions to a MySQL table called <strong>rights</strong>. The employee info is gathered from <strong>hs_hr_employee</strong> and saved to <strong>rights tog</strong>ether with an extra 'Permissions' column.</p>
  
  <p>It was working at first, you could save the data and when you refresh the page, the <strong>admin_bkp.php</strong> shows you the default value in the comboboxes as you had previously chosen. </p>
  
  <p>However, now it is returning the default value as <strong>'All'</strong> which is something I don't want. I want it to show the chosen value from before.</p>
  
  <p>The <strong>admin_php.bkp</strong> saves the values upon clicking the <strong>'Save'</strong> button</p>
  
  <p>This is the code:
  <strong>admin_bkp.php</strong></p>
  
  <pre><code> &lt;?php
  
  $connection = mysql_connect('localhost','admin','root');
  
  if( isset($_POST['submit']) )
  {
      if( isset( $_POST['cb_change'] ) &amp;&amp; is_array( $_POST['cb_change'] ))
      {
          foreach( $_POST['cb_change']  as $emp_number =&gt; $permission)
          {       
  echo "$permission";
              $sql = "UPDATE `rights` SET Permission='".mysql_real_escape_string($permission)."' WHERE emp_number='".mysql_real_escape_string($emp_number)."'";
              echo __LINE__.": sql: {$sql}\n";
              mysql_query( $sql );
          }
      }
  }
  ?&gt;
  &lt;p style="text-align: center;"&gt;
      &lt;span style="font-size:36px;"&gt;&lt;strong&gt;&lt;span style="font-family: trebuchet ms,helvetica,sans-serif;"&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;File Database - Administration Panel&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;p style="text-align: center;"&gt;
      &amp;nbsp;&lt;/p&gt;
  
  &lt;head&gt;
  &lt;style type="text/css"&gt;
  /*
  http://icant.co.uk/csstablegallery/index.php?css=71
  
  Data Tables and Cascading Style Sheets Gallery
  Title: Casablanca
  Author: RODrigo CASTilho Galv?o Ferreira - RODCAST
  URL: http://www.rodcast.com.br
  Update: 04/04/2008 10:51 AM
  */
  body{
  background: url('bg.gif');
  }
  table {
      color: #666;
      font: 0.8em/1.6em "Trebuchet MS",Verdana,sans-serif;
      border-collapse: collapse;
      background: #fff;
  }
  
  table,caption {
      margin: 0 auto;
      border-right: 0px solid #CCC;
      border-left: 0px solid #CCC;    
  
  }
  
  caption,th,td {
      border-left: 0;
      padding: 10px;
  
  }
  
  caption,thead th,tfoot th,tfoot td {
      background-color: #216dab;
      color: #FFF;
      font-weight: bold;
      text-transform: uppercase
  }
  
  thead th {
      background-color: #666;
      color: #fff;
      text-align: center
  }
  
  tbody th {
      padding: 20px 10px
  }
  
  tbody tr.odd {
      background-color: #F7F7F7;
      color: #666;
  
  }
  
  tbody a {
      padding: 1px 2px;
      color: #fff;
      text-decoration: none;
      border-bottom: 1px dotted #E63C1E;
      background: #7bafd9;
  }
  
  tbody a:active,tbody a:hover,tbody a:focus,tbody a:visited {
      color: #fff;
  
  }
  
  tbody tr:hover {
      background-color: #EEE;
      color: #333
  }
  
  tbody tr:hover a {
      /*background-color: #FFF*/
      color:fff;
  }
  
  tbody td+td+td+td a {
      color: #fff;
      font-weight: bold;
      border-bottom: 0;
  
  }
  
  tbody td+td+td+td a:active,tbody td+td+td+td a:hover,tbody td+td+td+td a:focus,tbody td+td+td+td a:visited {
      color: #fff
  }
  
  tbody td a[href="http://www.rodcast.com.br/"] {
      margin: 0 auto;
      display: block;
      width: 15px;
      height: 15px;
      background: transparent url('data:image/gif;base64,R0lGODlhDwAPAIAAACEpMf///yH5BAAAAAAALAAAAAAPAA8AAAIjjA8Qer0JmYvULUOlxXEjaEndliUeA56c97TqSD5pfJnhNxYAOw%3D%3D') no-repeat;
      text-indent: -999em;
      border-bottom: 0;
  
  }
  
  tbody a:visited:after {
      font-family: Verdana,sans-serif;
      content: "\00A0\221A"
  }
  &lt;/style&gt;
  &lt;/head&gt;
  
      &lt;form method="post" action="db_submit.php"&gt;
  
      &lt;?php 
  
  
          if (!$connection)
            {
            die('Could not connect: ' . mysql_error());
            }
  
          mysql_select_db('users', $connection);
  
          #mysql_query('INSERT into rights(Emp_num, ID, Name, Surname) SELECT emp_number, employee_id, emp_firstname, emp_lastname FROM hs_hr_employee');
  
  
          $result = mysql_query("SELECT emp_number, employee_id, emp_firstname, emp_lastname, Permissions FROM rights");
  
          mysql_query("INSERT INTO rights (emp_number, employee_id, emp_firstname, emp_lastname)
                      SELECT emp_number, employee_id, emp_firstname, emp_lastname
                      FROM hs_hr_employee
                      ON DUPLICATE KEY UPDATE employee_id = VALUES(employee_id), emp_number = VALUES(emp_number)
                      ");
  
          $duplicates = mysql_query("SELECT emp_number, employee_id, emp_firstname, emp_lastname, count(*) FROM rights GROUP BY emp_number, employee_id, emp_firstname, emp_lastname having count(*) &gt; 1");
  
          $count = mysql_num_rows($duplicates);
  
          if ($count &gt; 0) {
          while ($row = mysql_fetch_assoc($duplicates)) {
          $field = $row["emp_number"];
          $limit = $row["count(*)"] - 1;
          mysql_query("DELETE FROM rights WHERE emp_number='$field' LIMIT $limit");
          }
          mysql_free_result($duplicates);
          }           
  
  
          echo "&lt;center&gt;";
          /*
          echo "      
          &lt;table &gt;
          &lt;tr&gt;
          &lt;th&gt;Employee Number&lt;/th&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Surname&lt;/th&gt;
          &lt;th&gt;Permissions&lt;/th&gt;
          &lt;th&gt;Change&lt;/th&gt;
          &lt;/tr&gt;"; */
  
          echo "      
          &lt;table &gt;
          &lt;tr&gt;
          &lt;th&gt;Employee Number&lt;/th&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Surname&lt;/th&gt;        
          &lt;th&gt;Permissions&lt;/th&gt;
          &lt;/tr&gt;";
  
          while($row = mysql_fetch_array($result))
            {
            echo "&lt;tr&gt;";
            echo "&lt;td&gt;" . $row['emp_number'] . "&lt;/td&gt;";
            echo "&lt;td&gt;" . $row['employee_id'] . "&lt;/td&gt;";
            echo "&lt;td&gt;" . $row['emp_firstname'] . "&lt;/td&gt;";
            echo "&lt;td&gt;" . $row['emp_lastname'] . "&lt;/td&gt;";
            #echo "&lt;td&gt;" . $row['Permissions'] . "&lt;/td&gt;";
  
  
  
            echo "&lt;td&gt;
                        &lt;select&gt;
                           &lt;option value='All'&gt;All&lt;/option&gt; 
                           &lt;option value='Remote Gaming' selected='selected'&gt;Remote Gaming&lt;/option&gt; 
                           &lt;option value='Landbased Gaming'&gt;Landbased Gaming&lt;/option&gt;
                           &lt;option value='General Gaming'&gt;General Gaming&lt;/option&gt;
                        &lt;/select&gt;
                      &lt;/td&gt;
                      "; 
            echo "&lt;/tr&gt;" ;
            echo "&lt;input type='hidden' name='emp_id[]' value='". $row['employee_id'] ."'&gt;";
            }
  
  
          $selected = $row['Permissions'];
              $options = array(
                "Remote Gaming",
                "Landbased Gaming",
                "General Gaming"
              );
  
  
              foreach ($options as $option){
                if($option == $selected){
                  echo "&lt;option value='$option' selected='selected'&gt;$option&lt;/option&gt;";
                }else{
                  echo "&lt;option value='$option'&gt;$option&lt;/option&gt;";
                }
              }
            #echo "&lt;td&gt;" . $row['Change'] . "&lt;/td&gt;";
  
            echo "&lt;/table&gt;
                      &lt;p style='text-align: right;'&gt;
                          &lt;input name='Save_Btn' type='Submit' value='Save' /&gt;
                      &lt;/p&gt;
  
                  &lt;/center&gt;";
  
       mysql_close($connection);
  
      ?&gt;
  
  &lt;p style="text-align: center;"&gt;
      &amp;nbsp;&lt;/p&gt;
  &lt;p style="text-align: center;"&gt;
      &amp;nbsp;&lt;/p&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>db_submit.php:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;p&gt;Data submitted successfully.&lt;/p&gt;
  
  &lt;?php
  
  $connection = mysql_connect('localhost','admin','root');
  mysql_select_db('users', $connection);
  
  $cbchange = $_POST['cb_change'];
  $emp_id = $_POST['emp_id'];
  
  foreach($cbchange as $a =&gt; $b){
      echo $cbchange[$a] ." - ". $emp_id[$a];
      echo "&lt;br/&gt;";
  
      $query = "
  
                  UPDATE `rights`
                  SET `rights`.`Permissions`='".$cbchange[$a]."'
                  WHERE `rights`.`employee_id`='".$emp_id[$a]."'
                  ";
      mysql_query($query);
  }
  
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here are some images to give you a general idea of the setup.</p>
  
  <p><img src="https://i.stack.imgur.com/GL3Fm.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/JV1B4.png" alt="enter image description here"></p>
  
  <p><strong>Original Code:</strong></p>
  
  <pre><code>   &lt;?php
  
  $connection = mysql_connect('localhost','admin','root');
  
  if( isset($_POST['submit']) )
  {
      if( isset( $_POST['cb_change'] ) &amp;&amp; is_array( $_POST['cb_change'] ))
      {
          foreach( $_POST['cb_change']  as $emp_number =&gt; $permission)
          {       
  echo "$permission";
              $sql = "UPDATE `rights` SET Permission='".mysql_real_escape_string($permission)."' WHERE emp_number='".mysql_real_escape_string($emp_number)."'";
              echo __LINE__.": sql: {$sql}\n";
              mysql_query( $sql );
          }
      }
  }
  ?&gt;
  &lt;p style="text-align: center;"&gt;
      &lt;span style="font-size:36px;"&gt;&lt;strong&gt;&lt;span style="font-family: trebuchet ms,helvetica,sans-serif;"&gt;&lt;span style="color: rgb(0, 128, 128);"&gt;File Database - Administration Panel&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;p style="text-align: center;"&gt;
      &amp;nbsp;&lt;/p&gt;
  
  &lt;head&gt;
  &lt;style type="text/css"&gt;
  /*
  http://icant.co.uk/csstablegallery/index.php?css=71
  
  Data Tables and Cascading Style Sheets Gallery
  Title: Casablanca
  Author: RODrigo CASTilho Galv?o Ferreira - RODCAST
  URL: http://www.rodcast.com.br
  Update: 04/04/2008 10:51 AM
  */
  body{
  background: url('bg.gif');
  }
  table {
      color: #666;
      font: 0.8em/1.6em "Trebuchet MS",Verdana,sans-serif;
      border-collapse: collapse;
      background: #fff;
  }
  
  table,caption {
      margin: 0 auto;
      border-right: 0px solid #CCC;
      border-left: 0px solid #CCC;    
  
  }
  
  caption,th,td {
      border-left: 0;
      padding: 10px;
  
  }
  
  caption,thead th,tfoot th,tfoot td {
      background-color: #216dab;
      color: #FFF;
      font-weight: bold;
      text-transform: uppercase
  }
  
  thead th {
      background-color: #666;
      color: #fff;
      text-align: center
  }
  
  tbody th {
      padding: 20px 10px
  }
  
  tbody tr.odd {
      background-color: #F7F7F7;
      color: #666;
  
  }
  
  tbody a {
      padding: 1px 2px;
      color: #fff;
      text-decoration: none;
      border-bottom: 1px dotted #E63C1E;
      background: #7bafd9;
  }
  
  tbody a:active,tbody a:hover,tbody a:focus,tbody a:visited {
      color: #fff;
  
  }
  
  tbody tr:hover {
      background-color: #EEE;
      color: #333
  }
  
  tbody tr:hover a {
      /*background-color: #FFF*/
      color:fff;
  }
  
  tbody td+td+td+td a {
      color: #fff;
      font-weight: bold;
      border-bottom: 0;
  
  }
  
  tbody td+td+td+td a:active,tbody td+td+td+td a:hover,tbody td+td+td+td a:focus,tbody td+td+td+td a:visited {
      color: #fff
  }
  
  tbody td a[href="http://www.rodcast.com.br/"] {
      margin: 0 auto;
      display: block;
      width: 15px;
      height: 15px;
      background: transparent url('data:image/gif;base64,R0lGODlhDwAPAIAAACEpMf///yH5BAAAAAAALAAAAAAPAA8AAAIjjA8Qer0JmYvULUOlxXEjaEndliUeA56c97TqSD5pfJnhNxYAOw%3D%3D') no-repeat;
      text-indent: -999em;
      border-bottom: 0;
  
  }
  
  tbody a:visited:after {
      font-family: Verdana,sans-serif;
      content: "\00A0\221A"
  }
  &lt;/style&gt;
  &lt;/head&gt;
  
      &lt;form method="post" action="db_submit.php"&gt;
  
      &lt;?php 
  
  
          if (!$connection)
            {
            die('Could not connect: ' . mysql_error());
            }
  
          mysql_select_db('users', $connection);
  
          #mysql_query('INSERT into rights(Emp_num, ID, Name, Surname) SELECT emp_number, employee_id, emp_firstname, emp_lastname FROM hs_hr_employee');
  
  
          $result = mysql_query("SELECT emp_number, employee_id, emp_firstname, emp_lastname, Permissions FROM rights");
  
          mysql_query("INSERT INTO rights (emp_number, employee_id, emp_firstname, emp_lastname)
                      SELECT emp_number, employee_id, emp_firstname, emp_lastname
                      FROM hs_hr_employee
                      ON DUPLICATE KEY UPDATE employee_id = VALUES(employee_id), emp_number = VALUES(emp_number)
                      ");
  
          $duplicates = mysql_query("SELECT emp_number, employee_id, emp_firstname, emp_lastname, count(*) FROM rights GROUP BY emp_number, employee_id, emp_firstname, emp_lastname having count(*) &gt; 1");
  
          $count = mysql_num_rows($duplicates);
  
          if ($count &gt; 0) {
          while ($row = mysql_fetch_assoc($duplicates)) {
          $field = $row["emp_number"];
          $limit = $row["count(*)"] - 1;
          mysql_query("DELETE FROM rights WHERE emp_number='$field' LIMIT $limit");
          }
          mysql_free_result($duplicates);
          }           
  
  
          echo "&lt;center&gt;";
          /*
          echo "      
          &lt;table &gt;
          &lt;tr&gt;
          &lt;th&gt;Employee Number&lt;/th&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Surname&lt;/th&gt;
          &lt;th&gt;Permissions&lt;/th&gt;
          &lt;th&gt;Change&lt;/th&gt;
          &lt;/tr&gt;"; */
  
          echo "      
          &lt;table &gt;
          &lt;tr&gt;
          &lt;th&gt;Employee Number&lt;/th&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Surname&lt;/th&gt;        
          &lt;th&gt;Permissions&lt;/th&gt;
          &lt;/tr&gt;";
  
          while($row = mysql_fetch_array($result))
            {
            echo "&lt;tr&gt;";
            echo "&lt;td&gt;" . $row['emp_number'] . "&lt;/td&gt;";
            echo "&lt;td&gt;" . $row['employee_id'] . "&lt;/td&gt;";
            echo "&lt;td&gt;" . $row['emp_firstname'] . "&lt;/td&gt;";
            echo "&lt;td&gt;" . $row['emp_lastname'] . "&lt;/td&gt;";
            #echo "&lt;td&gt;" . $row['Permissions'] . "&lt;/td&gt;";
  
            echo "&lt;td&gt; &lt;select name='cb_change[]' SELECTED VALUE=".$row['Permissions']."&gt;
            &lt;option value='All'&gt;All&lt;/option&gt; 
            &lt;option value='Remote Gaming'&gt;Remote Gaming&lt;/option&gt; 
            &lt;option value='Landbased Gaming'&gt;Landbased Gaming&lt;/option&gt;
            &lt;option value='General Gaming'&gt;General Gaming&lt;/option&gt;
            &lt;/select&gt; &lt;/td&gt;"; 
            echo "&lt;/tr&gt;" ;
            echo "&lt;input type='hidden' name='emp_id[]' value='". $row['employee_id'] ."'&gt;";
            }
  
            #echo "&lt;td&gt;" . $row['Change'] . "&lt;/td&gt;";
  
            echo "&lt;/table&gt;
                      &lt;p style='text-align: right;'&gt;
                          &lt;input name='Save_Btn' type='Submit' value='Save' /&gt;
                      &lt;/p&gt;
  
                  &lt;/center&gt;";
  
       mysql_close($connection);
  
      ?&gt;
  
  &lt;p style="text-align: center;"&gt;
      &amp;nbsp;&lt;/p&gt;
  &lt;p style="text-align: center;"&gt;
      &amp;nbsp;&lt;/p&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Can you kindly point me in the right direction?</p>