title: Save html code to mysql table with php and jquery ajax
body: <p>Im trying to clone a div's content with jquery. After it is cloned i am sending it to a php page to be processed with Jquery Ajax. The php page saves it to a mysql database table. Then i need to retrieve it from the table on a different page and load it in another div. The mysql table cell is a blob that i save this html too. When i retrieve the table it echo's [object Object]. So i not usre if i am sending it to the save_invoice.php correctly or im not saving it to database correctly or last im not retrieving it correctly. </p>
  
  <p>Html div: invoice.php</p>
  
  <pre><code>&lt;div id="invoice_content"&gt;
    &lt;table&gt;
      &lt;tr&gt;&lt;td&gt;Html Example&lt;/td&gt;&lt;/tr&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Jquery Code:</p>
  
  <pre><code> $(document).on('click', "#clone", function () {
   var printContents = $("#invoice_content").clone(true, true);
  
    //var $data = 'invoice=' + escape(printContents);
  
    var $data = $(printContents).serialize();
  
   $.ajax({ url: "functions/insert_html.php",
          type: "POST",
          dataType:"html",
          data:$data,
            success:function(obj){
              alert(obj);
            }
      });      
  
   });
  </code></pre>
  
  <p>php: save_invoice.php </p>
  
  <pre><code> if (isset($_POST['invoice'])) {
  
      $html = $_POST['invoice'];  
  
    $sql = "INSERT INTO `html table` (html) 
       VALUES ('" . mysql_real_escape_string($html) . "')";
  
      if (mysqli_query($conn, $sql)) {
          echo "New record created successfully";
      } else {
          echo "Error: " . $sql . "&lt;br&gt;" . mysqli_error($conn);
      }
  
     mysqli_close($conn);     
    }
  </code></pre>
  
  <p>php: view_invoice.php </p>
  
  <pre><code>   if(isset($_GET)){
     $id = $_GET['id'];
  
     $sql = "SELECT html FROM `html table` WHERE id = '".$id."'";
       $result = mysqli_query($conn, $sql);
  
     while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
         $html_id = $row["html"];
          }
  
      mysqli_close($conn);   
  
     }
  
      &lt;div id="invoice_content"&gt;                 
         &lt;?php echo $html_id; ?&gt;
      &lt;/div&gt;
  </code></pre>