title: How to save html values to MySQL using ajax?
body: <p>I'm trying to make an HTML table dynamically. I'm just testing with sample, but It's not working as well as I expected.  So, I'm asking this question. Let me show you this simple table, it is MySQL database. and I create HTML table. </p>
  
  <p><a href="https://i.stack.imgur.com/m2Usb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m2Usb.png" alt="enter image description here"></a></p>
  
  <p>What I want to do is when I click some node, like a '250', this number will be editable. Edited data will be saved to the MySQL database. So I use the <code>contenteditable="true"</code> attribute value, and when this node loses focus, run some JavaScript function that new data will be saved. </p>
  
  <p>But... It's not working well. Honestly I don't know what the problem is exactly. Google chrome spit up "Uncaught Syntax Error, Unexpected token } ", But I couldn't find what the actual problem is. I'm newbie on this... Could you some guys help me?   </p>
  
  <p><strong>sample.html</strong></p>
  
  <pre><code>&lt;body&gt;
  &lt;?php
  
  require_once("db_connect.php");
  $sql = "SELECT * FROM test";
  $result = $conn-&gt;query($sql);
  ?&gt;
  
  &lt;table border="1" style="border-collapse:collapse;"&gt;
  &lt;thead&gt;
  &lt;tr&gt;&lt;th&gt;name&lt;/th&gt;&lt;th&gt;price&lt;/th&gt;&lt;/tr&gt;
  &lt;/thead&gt;
  
  &lt;tbody&gt;
  &lt;?php
      while($row = $result-&gt;fetch_assoc()){
          echo
          "&lt;tr&gt;
          &lt;td contenteditable='true' onBlur='saveToDatabase(this,'name','$id')'&gt;{$row['name']}&lt;/td&gt;
          &lt;td contenteditable='true' onBlur='saveToDatabase(this,'price','$id')'&gt;{$row['price']}&lt;/td&gt;
          &lt;/tr&gt;\n";
        }
  ?&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  
  
  &lt;script&gt;
  function saveToDatabase(editableObj, column, id) {
      $.ajax({
          url: "saveedit.php",
          type: "POST",
          data:'column='+column+'&amp;editval='+editableObj.innerHTML+'&amp;id='+id,
          success: function(data){
              $(editableObj).css("background","#FDFDFD");
          } 
     });
  }
  &lt;/script&gt;
  
  
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>saveedit.php</strong></p>
  
  <pre><code>&lt;?php
  
  require_once("db_connect.php");
  $result = mysql_query("UPDATE test SET ". $_POST["column"]. " = '".$_POST["editval"]."' WHERE  id=".$_POST["id"]);
  
  ?&gt;
  </code></pre>