title: Sending and deleting records to database with a drag and drop table
body: <p>I have three db tables.</p>
  
  <p>-Paid</p>
  
  <p>-Partially Paid</p>
  
  <p>-Owes</p>
  
  <p>When someone registers for an account I send their user_id, name, etc to my 'Owes' db table and then output their name into a drag and drop table I have in the 'Owes' column. As of now if I move anyone's name to any other category (Paid/Partially paid) I am not sure how to delete that record from the Owes db and insert the name into the new db table so the changes are permanent.</p>
  
  <p>What's really throwing me off is how to do it with the drag and drop table. I'm not sure how to apply the logic that when something is dropped into that column that the past record is deleted and a new one is added to that specific table or how to make the changes without a submit button or page reload.</p>
  
  <p>What is a way I can do this and how could I structure it?</p>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  //Payment Section
  
      $con = mysqli_connect("localhost", "root", "", "db");
      $paid_run = mysqli_query($con,"SELECT * FROM paid ORDER BY id DESC");
      $partially_paid_run = mysqli_query($con,"SELECT * FROM partial_payment ORDER BY id DESC");
      $owes_run = mysqli_query($con,"SELECT * FROM owes ORDER BY id DESC");
      $paid_numrows = mysqli_num_rows($paid_run);
      $partially_paid_numrows = mysqli_num_rows($partially_paid_run);
      $owes_numrows = mysqli_num_rows($owes_run);
  
          if($paid_numrows &gt; 0){
              while($row = mysqli_fetch_assoc($paid_run)){
                  $paid_id = $row['user_id'];
                  $paid_name = $row['name'];
              }
          }
  
      if($partially_paid_numrows &gt; 0){
              while($row = mysqli_fetch_assoc($partially_paid_run)){
                  $partially_paid_id = $row['user_id'];
                  $partially_paid_name = $row['name'];
                  $partially_paid_amount = $row['payment'];
              }
          }
  
      if($owes_numrows &gt; 0){
              while($row = mysqli_fetch_assoc($owes_run)){
                  $owes_id = $row['user_id'];
                  $owes_name = $row['name'];
              }
          }
  ?&gt;  
  $(function() {
      $( "#paid, #partially_paid, #owes" ).sortable({
        connectWith: ".tdPayment",
        remove: function(e, ui) {
          var $this = $(this);
          var childs = $this.find('div');
          if (childs.length === 0) {
             $this.text("Nothing");
          }
        },
        receive: function(e, ui) {
          $(this).contents().filter(function() {
              return this.nodeType == 3; //Node.TEXT_NODE
           }).remove();
        },
      }).disableSelection();
    });
  </code></pre>
  
  <p>Table</p>
  
  <pre><code>&lt;table class="paymentTable" id="dragTable"&gt;
          &lt;tr&gt;
              &lt;th class="thPayment"&gt;Paid&lt;/th&gt;
              &lt;th class="thPayment"&gt;Partially Paid&lt;/th&gt;
              &lt;th class="thPayment"&gt;Owes&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="tdPayment" id="paid"&gt;
                              &lt;div&gt;
              &lt;?php
                  if ($paid_name == true) {
                      echo $paid_name;
                  } else {
                      echo "No one has paid";
                  }
              ?&gt;
                              &lt;/div&gt;
              &lt;/td&gt;
              &lt;td class="tdPayment" id="partially_paid"&gt;
              &lt;div&gt;
              &lt;?php 
                  if ($partially_paid__name == true) {
                      echo $partially_paid__name . " - " . $partially_paid_amount;
                  } else {
                      echo "No one has made a partial payment";
                  }
              ?&gt;  
              &lt;/div&gt;
              &lt;/td&gt;
              &lt;td class="tdPayment" id="owes"&gt;
              &lt;div&gt;
              &lt;?php
                  if ($owes_name == true) {
                      echo $owes_name;
                  } else {
                      echo "Everyone has paid something";
                  }
              ?&gt;  
              &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>