title: PHP does not save HTML code to database
body: <p>PHP 5.4 (recommended by my host)
  MySQL 5
  <em>I have no logs.</em></p>
  
  <p>I have a script that was working perfectly fine a week ago. I've made absolutely <strong>ZERO</strong> changes to it at all. It's a simple news system script.</p>
  
  <p>It use to allow saving with html text such as bold, italics, underline etc. When editing the news it would display it the same way it was saved. The only thing that changed was the <br />. It would be added before saving to the database but removed when displayed.</p>
  
  <p>This is the portion of the script that saves the information. I took out any information that was not valid to the question. Only displaying the content containing the issue.</p>
  
  <pre><code>&lt;?php require('check.php'); 
  require_once('settings.php');
  
  if (isset($_POST['update'])) {
  
      $id = htmlspecialchars(strip_tags($_POST['id']));
      $month = htmlspecialchars(strip_tags($_POST['month']));
      $date = htmlspecialchars(strip_tags($_POST['date']));
      $year = htmlspecialchars(strip_tags($_POST['year']));
      $time = htmlspecialchars(strip_tags($_POST['time']));
      $entry = $_POST['entry'];
      $avatar = $_POST['avatar'];
      $title = htmlspecialchars(strip_tags($_POST['title']));
  
  /*    $entry = nl2br($entry); */
      $entry = preg_replace("/\r\n|\r/", "&lt;br /&gt;", $entry);
  
      if (!get_magic_quotes_gpc()) {
          $title = addslashes($title);
          $entry = addslashes($entry);
      }
  
      $timestamp = strtotime ($month . " " . $date . " " . $year . " " . $time);
  
      $result = mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE my_blog SET timestamp='$timestamp', title='$title', entry='$entry', avatar='$avatar' WHERE id='$id' LIMIT 1") or print ("Can't update entry.&lt;br /&gt;" . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
  
      header("Location: ../entry.php?id=" . $id);
  
  }
  
  if (isset($_POST['delete'])) {
      $id = (int)$_POST['id'];
      $result = mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM my_blog WHERE id='$id'") or print ("&lt;p class=\"error\"Can't delete entry.&lt;br /&gt;" . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . "&lt;/p&gt;");
      if ($result != false) {
          print "&lt;p class=\"success\"&gt;The entry has been successfully deleted from the database.&lt;/p&gt;";
          exit;
      }
  }
  
  if (!isset($_GET['id']) || empty($_GET['id']) || !is_numeric($_GET['id'])) {
      die("Invalid entry ID.");
  }
  else {
      $id = (int)$_GET['id'];
  }
  
  require_once("header.php");
  $result = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM my_blog WHERE id='$id'") or print ("Can't select entry.&lt;br /&gt;" . $sql . "&lt;br /&gt;" . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
  
  while ($row = mysqli_fetch_array($result)) {
      $old_timestamp = $row['timestamp'];
      $old_title = stripslashes($row['title']);
      $old_entry = nl2br($row['entry']);
      $old_avatar = stripslashes($row['avatar']);
      $old_password = $row['password'];
  
      $old_title = str_replace('"','\'',$old_title);
      $old_entry = str_replace('\r\n', '&lt;br /&gt;', $old_entry);
  
      $old_month = date("F",$old_timestamp);
      $old_date = date("d",$old_timestamp);
      $old_year = date("Y",$old_timestamp);
      $old_time = date("H:i",$old_timestamp);
  }
  ?&gt;
  &lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
  &lt;p&gt;&lt;input class="form-control" type="hidden" name="id" value="&lt;?php echo $id; ?&gt;" /&gt;
  &lt;b&gt;&lt;label for="month"&gt;Date:&lt;/label&gt;&lt;/b&gt;
  &lt;table width=100%&gt; 
  &lt;tr&gt;
  &lt;td width="25%"&gt;&lt;input class="form-control" type="text" name="date" id="date" size="2" value="&lt;?php echo $old_date; ?&gt;" /&gt;&lt;/td&gt;
  &lt;td width="50%"&gt;&lt;select class="form-control" name="month" id="month"&gt;
  &lt;option value="&lt;?php echo $old_month; ?&gt;"&gt;&lt;?php echo $old_month; ?&gt;&lt;/option&gt;
  &lt;option value="January"&gt;January&lt;/option&gt;
  &lt;option value="February"&gt;February&lt;/option&gt;
  &lt;option value="March"&gt;March&lt;/option&gt;
  &lt;option value="April"&gt;April&lt;/option&gt;
  &lt;option value="May"&gt;May&lt;/option&gt;
  &lt;option value="June"&gt;June&lt;/option&gt;
  &lt;option value="July"&gt;July&lt;/option&gt;
  &lt;option value="August"&gt;August&lt;/option&gt;
  &lt;option value="September"&gt;September&lt;/option&gt;
  &lt;option value="October"&gt;October&lt;/option&gt;
  &lt;option value="November"&gt;November&lt;/option&gt;
  &lt;option value="December"&gt;December&lt;/option&gt;
  &lt;/select&gt;&lt;/td&gt;
  &lt;td width="25%"&gt;&lt;select class="form-control" name="year" id="year"&gt;
  &lt;option value="&lt;?php echo $old_year; ?&gt;"&gt;&lt;?php echo $old_year; ?&gt;&lt;/option&gt;
  &lt;option value="2013"&gt;2013&lt;/option&gt;
  &lt;option value="2014"&gt;2014&lt;/option&gt;
  &lt;option value="2015"&gt;2015&lt;/option&gt;
  &lt;option value="2016"&gt;2016&lt;/option&gt;
  &lt;option value="2017"&gt;2017&lt;/option&gt;
  &lt;option value="2018"&gt;2018&lt;/option&gt;
  &lt;option value="2019"&gt;2019&lt;/option&gt;
  &lt;option value="2020"&gt;2020&lt;/option&gt;
  &lt;/select&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;b&gt;&lt;label for="time"&gt;Time:&lt;/label&gt;&lt;/b&gt;&lt;/td&gt;
  &lt;td&gt;&lt;b&gt;&lt;label for="title"&gt;Title:&lt;/label&gt;&lt;/b&gt;&lt;/td&gt;
  &lt;td&gt;&lt;b&gt;&lt;label for="avatar"&gt;Icon:&lt;/label&gt;&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;input class="form-control" type="text" name="time" id="time" size="5" value="&lt;?php echo $old_time; ?&gt;" /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input class="form-control" type="text" name="title" id="title" value="&lt;?php echo $old_title; ?&gt;" size="40" /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input class="form-control" type="text" name="avatar" id="avatar" size="40" maxlength="100" value="&lt;?php echo $old_avatar; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;p&gt;&lt;textarea class="form-control" cols="80" rows="20" name="entry" id="entry"&gt;&lt;?php echo $old_entry; ?&gt;&lt;/textarea&gt;&lt;/p&gt;
  &lt;p&gt;&lt;button type="submit" name="update" id="update" class="btn btn-default"&gt;Update!&lt;/button&gt;&lt;/p&gt;
  &lt;/form&gt;
  &lt;p&gt;&lt;strong&gt;Before deleting, be absolutely sure - there is no confirmation nor is there any way to reverse deletion!&lt;/strong&gt;&lt;br /&gt;
  &lt;small&gt;(You may be shown your entry again after deleting - do not worry, it HAS been deleted.  Check the main page of the blog if you are still unsure.&lt;/small&gt;&lt;/p&gt;
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
  &lt;input type="hidden" name="id" id="id" value="&lt;?php echo $id; ?&gt;" /&gt;
  &lt;button type="submit" name="delete" id="delete" class="btn btn-default"&gt;Yes, I am absolutely and positively sure I want to delete this entry.&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;?php
  require_once("footer.php");
  ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
  ?&gt;
  </code></pre>
  
  <p>I've tried to see if this was a host issue but apparently many people across many host that use this specific script are having this issue. It all started at the exact same time for everyone. But not one person has a clue what is going on. Everyone is running at least on PHP 5.4 nothing older.</p>
  
  <p>It's just really strange how something that was working stopped working and was looking for some insight on what could be the issue. Google has been of no help and I can't find anything here on stack overflow.</p>
  
  <p>Please note that I have tried changing the way of saving the information. I know using nl2br() should actually not be used to save information to the database only to display information from the datasbase. But I did not write the script and it is no longer being kept by the original developer of the script.</p>
  
  <p><strong>I've converted everything to mysqli_ with no changes to the problem.</strong></p>
  
  <p>settings.php</p>
  
  <pre><code>&lt;?php
      $users = array($user =&gt; md5($pass));
      $salt = substr(md5(date("F")), 8);
      $cards_seperate_directory = FALSE;
  
      $connect = mysql_connect("$db_server", "$db_user", "$db_password")
          or die( DATABASE_CONNECT_ERROR . mysql_error() );
      mysql_select_db("$db_database", $connect)
          or die( DATABASE_CONNECT_ERROR . mysql_error() );
  
      function CleanUp($data) {
          $data = trim(htmlentities(strip_tags($data)));
          return $data;
          }
  
      function escape_sql($sql) {
          if (get_magic_quotes_gpc()) $sql = stripslashes($sql);
          return mysql_real_escape_string($sql);
          }
  ?&gt;
  </code></pre>