title: how to update HTML code into a MySQL field
body: <p>PHP Version: 5.3.19
  MYSQL Version: 5.0.96</p>
  
  <p>I have a database table with a field that contains xml data:</p>
  
  <p>XML DATA:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
      &lt;book&gt;
          &lt;page&gt;
              &lt;data&gt;Page 1&lt;/data&gt;
          &lt;/page&gt;
          &lt;page&gt;
              &lt;data&gt;Page 2&lt;/data&gt;
          &lt;/page&gt;
          &lt;page&gt;
              &lt;data&gt;Page 3&lt;/data&gt;
          &lt;/page&gt;
      &lt;/book&gt;
  </code></pre>
  
  <p>I have successfully had the xml data displayed, now I'm trying to update it with php</p>
  
  <p>PHP CODE:</p>
  
  <pre><code>$id = 1;
      $fav_id = $id;
      $userid = 1;
      $data_update = '&lt;p style="text-align: center;"&gt;&lt;span style="text-decoration: underline; font-size: xx-large;"&gt;&lt;em&gt;&lt;strong&gt;Title&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;';
      $page_number = 0;
  
      mysql_select_db($database_main, $main);
      $query_Recordset1 = "SELECT * FROM projects WHERE id = $id";
      $Recordset1 = mysql_query($query_Recordset1, $main) or die(mysql_error());
      $row_Recordset1 = mysql_fetch_assoc($Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  
      $xmldata = (string)$row_Recordset1['projectData'];
      $parsed = simplexml_load_string($xmldata);
      $data = $parsed-&gt;xpath('//data');
          $data[$page_number] = $data_update;
  
      $x = 0;
      $array_length = count($data);
      while($x &lt; $array_length){
              if($x==0){
                  $finalData .= '&lt;?xml version="1.0"?&gt;&lt;book&gt;';
              }
              $finalData .= "&lt;page&gt;&lt;data&gt;$data[$x]&lt;/data&gt;&lt;/page&gt;";
              if($x==$array_length-1){
                  $finalData .= "&lt;/book&gt;";    
              }
              $x++;
  
      }
      $FinalData = mysql_real_escape_string($finalData);
          $updateSQL = "UPDATE projects SET projectData=$finalData  WHERE id=$fav_id";
          mysql_select_db($database_main, $main);
      $Result1 = mysql_query($updateSQL, $main) or die(mysql_error());
  </code></pre>
  
  <p>I want the end result to be:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
      &lt;book&gt;
          &lt;page&gt;
              &lt;data&gt;
                  &lt;p style="text-align: center;"&gt;
                      &lt;span style="text-decoration: underline; font-size: xx-large;"&gt;
                          &lt;em&gt;&lt;strong&gt;Title&lt;/strong&gt;&lt;/em&gt;
                      &lt;/span&gt;
                  &lt;/p&gt;
              &lt;/data&gt;
          &lt;/page&gt;
          &lt;page&gt;
              &lt;data&gt;Page 2&lt;/data&gt;
          &lt;/page&gt;
          &lt;page&gt;
              &lt;data&gt;Page 3&lt;/data&gt;
          &lt;/page&gt;
      &lt;/book&gt;
  </code></pre>
  
  <p>although when i try <code>addslashes()</code> and <code>mysql_real_escape_string()</code> i get:</p>
  
  <p>DATA:</p>
  
  <pre><code>&lt;p center;\\\"="" style="\\\"text-align:"&gt;
      &lt;span xx-large;\\\"="" font-size:="" underline;="" style="\\\"text-decoration:"&gt;
          &lt;em&gt;
              &lt;strong&gt;Title&lt;/strong&gt;
          &lt;/em&gt;
      &lt;/span&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>my question is why are those two functions [<code>addslashes()</code> and <code>mysql_real_escape_string()</code>] giving me the result above, and how do I prevent it from happening?</p>