title: Editable database table with PHP+Ajax+jQuery
body: <p>I have a database named "guests" with two columns: Seat and Name. 
  I want to show this database in a php page where the user can double click in the "name" value and edit it, updating the database when he click somewhere else (blur it).</p>
  
  <p>The PHP: </p>
  
  <pre><code>&lt;?php
  include "connect.php";
  $result = mysqli_query($con, "SELECT * FROM guests");
  echo "&lt;table&gt;";
  while($row = mysqli_fetch_assoc($result)){
  
  echo "&lt;tr&gt;&lt;td contenteditable='true' onClick='showEdit(this);' onBlur='saveToDatabase(this,'Name','".$row['seat']."')'&gt;" . $row['Name'] . "&lt;/td&gt;
  
  &lt;td&gt;" . $row['seat'] . "&lt;/td&gt;&lt;/tr&gt;";
  }
  echo "&lt;/table&gt;";
  ?&gt;
  </code></pre>
  
  <p>The jQuery:</p>
  
  <pre><code>&lt;script&gt;
  function saveToDatabase(editableObj,what,where) {
      $(editableObj).css("background","#FFF url(loaderIcon.gif) no-repeat right");
      $.ajax({
          url: "handle.php",
          type: "POST",
          data:'what='+what+'&amp;newvalue='+editableObj.innerHTML+'&amp;where='+where,
          success: function(data){
              $(editableObj).css("background","#FDFDFD");
          }
     });
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>The server side (handle.php):</p>
  
  <pre><code>&lt;?php
  include "connect.php";
  $what = $_POST["what"];
  $newvalue = $_POST["newvalue"];
  $where = $_POST["where"];
  $sql = "UPDATE guests SET $what='$newvalue' WHERE seat='$where'";
  if ($con-&gt;query($sql) === TRUE) {
     header("Location: success.php");
  } else {
      header("Location: error.php");
  }
  ?&gt;
  </code></pre>
  
  <p>Currently, after the user edit the "name" value and click somewhere else, nothing happens, and the database is not updated. </p>