title: PHP MYSQL Insert HTML into MYSQL database
body: <p>How can you store html code in a mysql database? I can find everywhere where people can do it, but noone says how. I know i need to strip the data using "mysqli_real_escape_string" played with the example but have NO idea how to actually do it. I simply placed the code as shown below but it just game me an error. I know its because the HTML code has "" but i need those to be loaded when the page loads so how do i insert the code into the database? A link or something would be amazing.</p>
  
  <p>EDIT: Here is the full code, its not entering the information into the database, but is not giving any errors.</p>
  
  <pre><code>&lt;?php
      include_once('global.php');
  
      $city = ("&lt;div id='body_sidebar'&gt;
          &lt;ul&gt;
              &lt;li class='sidebar_service_space'&gt;&amp;nbsp;&lt;/li&gt;
              &lt;li class='sidebar_service_title'&gt;About Malware&lt;/li&gt;
              &lt;li&gt;&lt;a href='&lt;?php echo '$home' ?&gt;/services/malware/what-is-malware.html'&gt;What is Malware?&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href='&lt;?php echo '$home' ?&gt;/services/malware/common-signs.html'&gt;Common Signs of Malware&lt;/a&gt;&lt;/li&gt;
              &lt;li class='sidebar_service_space'&gt;&amp;nbsp;&lt;/li&gt;
  
              &lt;li class='sidebar_service_title'&gt;Malware Removal&lt;/li&gt;
              &lt;li&gt;&lt;a href='&lt;?php echo '$home' ?&gt;/services/malware/virus-removal.html'&gt;Virus Removal&lt;/a&gt;
                  &lt;a class='tooltip' href='/knowledge_base/virus_removal.php'&gt;&lt;img id='viruses' src='&lt;?php print'$style_images' ?&gt;/question.jpg' /&gt;
                  &lt;span class='custom info'&gt;&lt;img src='&lt;?php print'$style_images' ?&gt;/info.png' alt='Information' height='48' width='48' /&gt;
                  &lt;em&gt;Viruses&lt;/em&gt;
                      The computer virus is the most infamous form of malware. It is a self replicating program that infects a system without authorization. Once installed, it will execute itself, infect system files, and attempt to propagate to other systems. The impact of a virus ranges widely from slow system performance to wiping out every file on your computer. &lt;br /&gt;&lt;br /&gt;
                      &lt;font style='text-align:right; padding-left:150px; margin-top:15px;'&gt;Click the icon for more information...&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
              &lt;li&gt;&lt;a href='&lt;?php echo '$home' ?&gt;/services/malware/worm-removal.html'&gt;Worm Removal&lt;/a&gt;
                  &lt;a class='tooltip' href='/knowledge_base/worm_removal.html'&gt;&lt;img id='worm' src='&lt;?php print'$style_images' ?&gt;/question.jpg' /&gt;
                  &lt;span class='custom info'&gt;&lt;img src='&lt;?php print'$style_images' ?&gt;/info.png' alt='Information' height='48' width='48' /&gt;
                  &lt;em&gt;Worms&lt;/em&gt;
                      A computer worm is a self-replicating computer program. It uses a network to send copies of itself to 
      other computers on the network and it may do so without any user intervention. Worms usually exploit a 
      known or zero-day vulnerability that allows them to execute their copies on computers on the same 
      network.&lt;br /&gt;&lt;br /&gt;
                      &lt;font style='text-align:right; padding-left:150px; margin-top:15px;'&gt;Click the icon for more information...&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
              &lt;li&gt;&lt;a href='&lt;?php echo '$home' ?&gt;/services/malware/adware-removal.html'&gt;Adware Removal&lt;/a&gt;
                  &lt;a class='tooltip' href='/knowledge_base/adware_removal.html'&gt;&lt;img id='adware' src='&lt;?php print'$style_images' ?&gt;/question.jpg' /&gt;
                  &lt;span class='custom info'&gt;&lt;img src='&lt;?php print'$style_images' ?&gt;/info.png' alt='Information' height='48' width='48' /&gt;
                  &lt;em&gt;Adware&lt;/em&gt;
                      Adware is a program that causes the host computer to display advertisements that the user did not request. These are frequently in the form of pop-up ads that appear while browsing the Internet and pop-under ads that open in a window hidden beneath the Internet browser's window, according to security4web.com. Another version of adware is a toolbar that attaches to an Internet browser search ability.&lt;br /&gt;&lt;br /&gt;
                      &lt;font style='text-align:right; padding-left:150px; margin-top:15px;'&gt;Click the icon for more information...&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
              &lt;li&gt;&lt;a href='&lt;?php echo '$home' ?&gt;/services/malware/spyware-removal.html'&gt;Spyware Removal&lt;/a&gt;
                  &lt;a class='tooltip' href='/knowledge_base/spyware_removal.html'&gt;&lt;img id='spyware' src='&lt;?php print'$style_images' ?&gt;/question.jpg' /&gt;
                  &lt;span class='custom info'&gt;&lt;img src='&lt;?php print'$style_images' ?&gt;/info.png' alt='Information' height='48' width='48' /&gt;
                  &lt;em&gt;Spyware&lt;/em&gt;
                      Spyware collects information from a host computer and sends it to the creator of the program. Spyware can infect a computer as a result of surfing a website that installs it or even as part of programs a user knowingly downloads to use for a different purpose, according to security4web.com. The website notes that freeware (free software) and Internet links advertising spyware-removal programs frequently install spyware.&lt;br /&gt;&lt;br /&gt;
                      &lt;font style='text-align:right; padding-left:150px; margin-top:15px;'&gt;Click the icon for more information...&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
              &lt;li&gt;&lt;a href='&lt;?php echo '$home' ?&gt;/services/malware/rootkit-removal.html'&gt;Rootkit Removal&lt;/a&gt;
                  &lt;a class='tooltip' href='/knowledge_base/rootkit_removal.html'&gt;&lt;img id='spyware' src='&lt;?php print'$style_images' ?&gt;/question.jpg' /&gt;
                  &lt;span class='custom info'&gt;&lt;img src='&lt;?php print'$style_images' ?&gt;/info.png' alt='Information' height='48' width='48' /&gt;
                  &lt;em&gt;Rootkit&lt;/em&gt;
                      Rootkits can make it difficult to discover that your computer has been infected by other types of malware. According to h-online.com, a rootkit manipulates files so they are difficult to discover on your computer. This makes it a challenge to find out if a malware process or file is running in the background on your computer because a rootkit program may be preventing you from finding it by browsing folders or searching on your computer file system.&lt;br /&gt;&lt;br /&gt;
                      &lt;font style='text-align:right; padding-left:150px; margin-top:15px;'&gt;Click the icon for more information...&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
              &lt;li&gt;&lt;a href='&lt;?php echo '$home' ?&gt;/services/malware/trojan-removal.html'&gt;Trojan Horse Removal&lt;/a&gt;
                  &lt;a class='tooltip' href='/knowledge_base/trojan_removal.html'&gt;&lt;img id='spyware' src='&lt;?php print'$style_images' ?&gt;/question.jpg' /&gt;
                  &lt;span class='custom info'&gt;&lt;img src='&lt;?php print'$style_images' ?&gt;/info.png' alt='Information' height='48' width='48' /&gt;
                  &lt;em&gt;Trojan Horse&lt;/em&gt;
                      A trojan horse is unlike a virus or a worm because it cannot replicate itself, according to spamlaws.com. Instead, it executes itself, and the execution of the file can install additional forms of malware, such as viruses or worms. It can also delete files, eliminate access to specific websites and damage files on the computer.&lt;br /&gt;&lt;br /&gt;
                      &lt;font style='text-align:right; padding-left:150px; margin-top:15px;'&gt;Click the icon for more information...&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li class='sidebar_service_space'&gt;&amp;nbsp;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;span id='sidebar_contactus'&gt;Contact Us&lt;/span&gt;
          &lt;span id='sidebar_findus'&gt;Find Us&lt;/span&gt;
          &lt;hr /&gt;
          &lt;div id='sidebar_quote'&gt;
              &lt;div id='sidebar_quote_text'&gt;This is a small quote about someone loving who we are and what we do so they are praising us cuz well we are awesome.&lt;/div&gt;
          &lt;/div&gt;
          &lt;div id='sidebar_quote_arrow'&gt;
              &lt;div id='sidebar_quote_cite'&gt;
              Steven Hawkings
              Intelectual Badass
              &lt;a href='#'&gt;hiswebsite&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;");
  
      $city = mysqli_real_escape_string($cnx, $city);
  
      /* this query with escaped $city will work */
      if (mysqli_query($cnx, "INSERT into services (template_name, template_code) VALUES (sidebar_malware, '$city')")) {
          printf('%d Row inserted.\n', mysqli_affected_rows($cnx));
      }
  
      mysqli_close($cnx);
      ?&gt;
  </code></pre>