title: PHP multiple select - option data sending with ajax
body: <p>I want to change the status in the database, with a select dropdown field.
  I am sending with ajax. The first row is always working, but with multiple data i cant update the second, third..etc</p>
  
  <p>I tried with serialize(), but its not working.</p>
  
  <p>select from database:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;Title&lt;/title&gt;
  &lt;script src="https://code.jquery.com/jquery-1.11.3.js"&gt;&lt;/script&gt; 
  &lt;script type="text/javascript"&gt;
      $(document).ready(function(){
          $(".allbooks").change(function(){
              var allbooks = $(this).val();
              var dataString = "allbooks="+allbooks;
              $.ajax({
                  type: "POST",
                  data: dataString,
                  url: "get-data.php",
                  success: function(result){
                      $("#show").html(result);
                  }
              });
  
          });
      });
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
   &lt;?php
      define("HOST","localhost");
      define("USER","root");
      define("PASSWORD","");
      define("DATABASE","hotel");
      $euConn = mysqli_connect(HOST, USER, PASSWORD, DATABASE);
  
    $selectRooms = "SELECT * FROM proba WHERE status='inRoom'";
     $resultRooms = mysqli_query($euConn,$selectRooms);
       if (mysqli_num_rows($resultRooms) &gt; 0) {
      echo "&lt;div id='reserved' align='center'&gt;";
     While ($row = mysqli_fetch_array($resultRooms)) {
      echo $row[1];
      echo $row[0];
  ?&gt;
  
  &lt;select name="allbooks" id="allbooks"&gt;
  &lt;option name="years"&gt;Choose&lt;/option&gt;
  &lt;?php
  
  for($i=1; $i&lt;=19; $i++)
  {
      echo "&lt;option value=".$i."&gt;".$i."&lt;/option&gt;";
  }
  ?&gt;
   &lt;/select&gt;&lt;br /&gt;
  
  &lt;?php }
  
   }
  
  else
  echo "&lt;h4&gt;nothing in the db&lt;/h4&gt;&lt;/div&gt;";
  ?&gt;
  &lt;div id="show"&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and getting the results:</p>
  
  <pre><code>if(!empty($_POST["allbooks"])) {
  var_dump($_POST);
      $id = 2;
      //echo $_POST['modelS'];
      $room = $_POST['allbooks'];
      $sql2 = "UPDATE proba SET room='$room' WHERE id_reservation='$id'";
      $query = mysqli_query($euConn, $sql2);
  var_dump($query);
  }
  </code></pre>
  
  <p>How to change, or what would be a simple solution? Thanks for the help.</p>