www.webdeveloper.com
Results 1 to 5 of 5

Thread: new line storing problem

  1. #1
    Join Date
    May 2007
    Posts
    138

    new line storing problem

    hello , i am using a texbox to store a msg in my database
    and using these 2 functions before storing the post.

    PHP Code:
    $post=htmlentities($post);
    $post=mysql_real_escape_string($post); 
    however i am loosing new lines .

    line in the text box
    kamil
    baran
    tamer
    this is the way it is displayed when i call the post back from database
    kamil baran tamer
    any help?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,623
    I would recommend not using htmlentities for storing the text in the database, as you are then assuming that data will only ever be used for HTML. Instead use it after retrieving the data and specifically outputting it as [X]HTML. Then when you output it, you can also use the nl2br() function to add <br /> tags wherever there is a newline:
    PHP Code:
    echo nl2br(htmlentities($value_from_database)); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2007
    Posts
    138
    thanks alot its workin..
    i have another question.

    is

    PHP Code:
    $post=mysql_real_escape_string($post); 
    enough to avoid injection?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,623
    Yes (assuming you mean SQL injection).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    May 2007
    Posts
    138
    thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles