title: Updating table values using dropdown without using a submit button
body: <p>I'm trying to update the database using a dropdown list without using a submit button.</p>
  
  <p>Here's my dropdown:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;td&gt;
    &lt;label for=""&gt;&lt;/label&gt; 
    &lt;select style="font-family: Questrial;" name="status" required&gt;
     &lt;option disabled selected hidden&gt;Select Status&lt;/option&gt;
     &lt;option value="In Progress"&gt;In Progress&lt;/option&gt;
     &lt;option value="Closed: Cancelled"&gt;Closed: Cancelled&lt;/option&gt;
     &lt;option value="Closed: Solved"&gt;Closed: Solved&lt;/option&gt;
   &lt;/select&gt;
  &lt;/td&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here's the script:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script&gt;
    $(document).ready(function() {
      $('option[name="status"]').click(function() {
        var status = $(this).val();
        $.ajax({
          url: "update2.php",
          method: "POST",
          data: {
            status: status
          },
          success: function(data) {
            $('#result').html(data);
          }
        });
      });
    }); 
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And here's update2.php:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?php
  //Insert Data
   $hostname = "localhost";
   $username = "root";
   $password = "";
   $databasename = "companydb";
   
   try
   {
    $conn = new PDO("mysql:host=$hostname;dbname=$databasename",$username, $password);
    $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
   if(isset($_POST["status"]))
   {
    $query = "INSERT INTO tickets(status) VALUES (:status)";
    $statement = $conn-&gt;prepare($query);
    $statement-&gt;execute(
   array('status' =&gt; $_POST["status"])
   );
   
   $count = $statement-&gt;rowCount();
   if($count &gt; 0)
   {
    echo "Data Inserted Successfully..!";
   }
    else
   {
    echo "Data Insertion Failed";
   }
   }
  }
  
   catch(PDOException $error)
   {
    echo $error-&gt;getMessage();
   }
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Basically what I want to happen is to update the table values when I make a selection from the dropdown list.</p>
  
  <p>Currently, nothing happens when I make a selection. (No page reload, No error message, just nothing)</p>
  
  <p>Am I doing something wrong here?</p>
  
  <p>Also here's my table schema:</p>
  
  <p><a href="https://i.stack.imgur.com/de79H.png" rel="nofollow noreferrer">table schema</a></p>