title: Inserting text from textarea into MySQL database without losing formatting
body: <p>I am trying to add text from a textarea on my site into a MySQL database.</p>
  
  <p>Below is the PHP code that is adding the text to the database.</p>
  
  <pre><code>if (isset($_POST['text']))
  {
      $text = sanitizeString($_POST['text']);
      $text = preg_replace('/\s\s+/', ' ', $text);
  
      $query = "SELECT * FROM profiles WHERE user='$user'";
      if (mysql_num_rows(queryMysql($query)))
      {
          queryMysql("UPDATE profiles SET text='$text' where user='$user'");
      }
      else
      {
          $query = "INSERT INTO profiles VALUES('$user', '$text')";
          queryMysql($query);
      }
  
  }
  else
  {
      $query  = "SELECT * FROM profiles WHERE user='$user'";
      $result = queryMysql($query);
  
      if (mysql_num_rows($result))
      {
          $row  = mysql_fetch_row($result);
          $text = stripslashes($row[1]);
      }
      else $text = "";
  }
  
  $text = stripslashes(preg_replace('/\s\s+/', ' ', $text));
  </code></pre>
  
  <p>And below is the code of the form.</p>
  
  <pre><code>&lt;textarea name='text' cols='40' rows='3'&gt;$text&lt;/textarea&gt;&lt;br /&gt; 
  </code></pre>
  
  <p>But when the data is inputted, it shows it in the database correct but not showing it displayed properly. See the images below:</p>
  
  <p><em>The text that is entered</em></p>
  
  <p><img src="https://i.stack.imgur.com/sEbMh.png" alt="the text that is entered" title="the text that is entered"></p>
  
  <p><em>How the text is displayed on the page</em></p>
  
  <p><img src="https://i.stack.imgur.com/gLpHT.png" alt="this is how the text is displayed" title="this is how the text is displayed"></p>
  
  <p><em>How the text is in the database</em></p>
  
  <p><img src="https://i.stack.imgur.com/RLa7y.png" alt="this is the text in the database" title="this is the text in the database"></p>
  
  <p>This is the PHP code that displays the text on the page.</p>
  
  <pre><code>$result = queryMysql("SELECT * FROM profiles WHERE user='$user'");
  
      if (mysql_num_rows($result))
      {
          $row = mysql_fetch_row($result);
          echo stripslashes($row[1]) . "&lt;br clear=left /&gt;&lt;br /&gt;
  </code></pre>
  
  <p>Hope you can help!!</p>
  
  <p>EDIT: added extra php code</p>