Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:22:56+00:00 2026-05-23T12:22:56+00:00

I am trying to insert a description text field into the database. I was

  • 0

I am trying to insert a description text field into the database.

I was previously just doing something like this:

$group_description = mysql_real_escape_string($_POST['group_description']);

But it was creating problems because when I was taking things out of the database, they were being displayed with \n\r strings instead of new lines.

Here is an example of a page with that problem:

http://www.comehike.com/hikes/hiking_group.php?hiking_group_id=48

So I tried to fix it by adding nl2br like this:

$group_description = mysql_real_escape_string(nl2br($_POST['group_description']));

But that just inserted an extra line 🙁 Here is the example of the current problem:

http://www.comehike.com/hikes/hiking_group.php?hiking_group_id=50

Here is an example of an insert statement I use:

$insert_group_sql =  'INSERT INTO hiking_groups( title , group_description ) VALUES ( "'.$group_name.'" , "'.$group_description.'" ) ';

What is the proper way to do this?

Here is the code I use to display the $group_description

          //Convert all urls to links
          $group_description = preg_replace('#([\s|^])(www)#i', '$1http://$2', $group_description);
          $pattern = '#((http|https|ftp|telnet|news|gopher|file|wais):\/\/[^\s]+)#i';
          $replacement = '<a href="$1" target="_blank">$1</a>';
          $group_description = preg_replace($pattern, $replacement, $group_description);

          $group_description = str_replace("\'" , "'", $group_description );
          $group_description = nl2br($group_description);

          /* Convert all E-mail matches to appropriate HTML links */
          $pattern = '#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.';
          $pattern .= '[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i';
          $replacement = '<a href="mailto:\\1">\\1</a>';
          $group_description = preg_replace($pattern, $replacement, $group_description);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:22:57+00:00Added an answer on May 23, 2026 at 12:22 pm

    First, I suggest that you do as Spudley suggests, keep it in the original form in the database and format it once you display it.

    nl2br() should work, so I suggest that you check the input data to see exactly what is being input (which is easier to do if you don’t format it before you store it in the DB). What it do is it takes \n, \n\r, \r\n and \r and inserts a <br/> instead. You should check that for instance there is no space in between \n and \r.

    Also, make sure that you only use nl2br() in one place, since it doesn’t replace the new lines, it just inserts the <br/> (that is, if you do nl2br(nl2br($group_description)) you will get two <br/>)

    Update:

    I see in the additional code that when you display the description, you already have a nl2br(). You need to remove one of them, so that you only add the <br/>s once.

    Also, instead of this:

          $group_description = str_replace("\'" , "'", $group_description );
          $group_description = nl2br($group_description);
    

    Try this:

          $group_description = stripslashes($group_description);
          $group_description = nl2br($group_description);
    

    That should remove all the sanitizing that mysql_real_escape_string() did, which should solve the problem of the \n\r showing in the text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to insert a comment character into a string something similar to this:
This is the query I am trying: INSERT INTO Product (ProductName, Description, Brand, Size,
Trying to insert 315K Gif files into an Oracle 10g database. Everytime I get
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
So I've been trying to insert sql into this one specific table for the
We're trying a basic insert statement: INSERT INTO HOLIDAY (HOLIDAY_TYPE_CODE, CALENDAR_NAME, HOLIDAY_DATE, DESCRIPTION, CREATE_TS,
I am trying to insert some values into a database from a form submitted
i'm trying to insert some data on a database using this code: -(void)insertLocationOnDatabase:(LocationType *)aLocation
Am trying to insert XML into XML Column.. getting following error: . Msg 6819,
I am trying to INSERT INTO a table using the input from another table.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.