title: How to update the database, when changing a select option - PHP, AJAX
body: <p>I have a table that i made in php, now i want to let the user to change the access level of each user, using a dropdown menu (select/option). For example: </p>
  
  <p><a href="https://i.stack.imgur.com/CWub2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CWub2.png" alt="enter image description here"></a></p>
  
  <p>Once the user presses general it sends the request to ajax, changing/updating the database instantly.</p>
  
  <p><strong>admin.php</strong></p>
  
  <pre><code>    &lt;?php
  //database connection
  include("db_conn.php");
  include("session.php");
  
  session_start();
  
  $username = $_SESSION['logged_in']; //set the current user
  $query = "SELECT `ID`, `Username`,`Name`, `DOB`, `Email`, `Access` FROM `users`";
  
  $result =   $mysqli-&gt;query($query);
  $row=$result-&gt;fetch_array(MYSQLI_ASSOC);
  
  
      function show_table($myData)
      {
          echo "&lt;table border=1 id='staff_table'&gt;
          &lt;tr&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;th&gt;Username&lt;/th&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;DOB&lt;/th&gt;
          &lt;th&gt;Email&lt;/th&gt;
          &lt;th&gt;Access&lt;/th&gt;
          &lt;/tr&gt;";
          while ($row = $myData-&gt;fetch_array(MYSQLI_ASSOC))
          {   
              $access= $row['Access'];
              $access2;
  
  
                $access_data = 1; //admin = level 1
                $access_data2 = 2; //general = 2
              if($access == 1)
              {
                  $access = "Admin";
                  $access2 = "General";
  
                  $access_data = 1; //change when the page loads (depending what access level they are)
                  $access_data2 = 2; //change when the page loads
              }
              else
              {
  
                  $access = "General";
                  $access2 = "Admin";
  
                  $access_data = 2; //the reason i have these values is they 
                  $access_data2 = 1; //change depending on what the user's access level is once the page loads
              }
  
              echo "&lt;tr&gt;";
              echo "&lt;td&gt;" . $row['ID'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['Username'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['Name'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['DOB'] . "&lt;/td&gt;";
              echo "&lt;td&gt;" . $row['Email'] . "&lt;/td&gt;";
              echo "&lt;td id='" . $row['ID'] .  "'&gt;";
              echo "&lt;select name='admin_menu' class='admin_menu'&gt;"; 
              echo '&lt;option class="admin_option" value="' . $access_data2. '"&gt;' . $access . '&lt;/option&gt;';
              echo '&lt;option class="admin_option" value="' . $access_data. '"&gt;' . $access2 . '&lt;/option&gt;';
              echo "&lt;/select&gt;";
              echo "&lt;/td&gt;";
              echo "&lt;/tr&gt;";
          }
          echo "&lt;/table&gt;";
      }
  
  ?&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Admin Table&lt;/title&gt;
          &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"&gt;&lt;/script&gt;
          &lt;script&gt;
              $(document).ready(function(){
                  $('.admin_menu').change(function() {
                      id = $(this).parent().attr('id');
                      level = $('.admin_menu  option:selected').val();
                      var request = $.ajax({
                        url: "changeLevel.php",
                        method: "POST",
                        data: { id : id, level: level },
                        dataType: "html"
                        });
  
                      request.done(function() {
                         //location.reload(); //reload page (if it actually updates)
                      });
  
                      });
                  });
          &lt;/script&gt;   
      &lt;/head&gt;
  
  
      &lt;body&gt;
          &lt;h1&gt;Admin Table&lt;/h1&gt;
          &lt;?php show_table($result); ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>changeLevel.php</strong></p>
  
  <pre><code>&lt;?php
  include("db_conn.php");
  
  $id = $_POST['id'];
  $level = $_POST['level'];
  
      $queryUpdate="UPDATE users SET Access='$level' WHERE ID='$id'";
      $update = $mysqli-&gt;query($queryUpdate);
  ?&gt;
  </code></pre>
  
  <p>The user table is not updating, is there any other solution to this? Or can anyone see the problem? Thanks in advance, I'm pretty new to AJAX so all help is appreciated :) </p>