I have a form which allow user to enter a description or note. It's a textarea called note.

My problem is that when I test enter some note, if I manually press enter to separate paragraph. After I insert into database, extra <br> is added in where I put in the line break so makes my paragraph separate by two line breaks instead of one I manually put in.

Is there a way to do this without adding extra line breaks? Thanks a lot.

Here is the code I used to insert note to database:
$note = addslashes(trim($textarea));

Here is the code I used to display note:
$textarea = stripslashes($note);

(For example:

here is paragraph1, fasfdasdfasdfasdfasdfasdfasdfasdfasdfasdfsdfsdfsadfasdfasdfsdfsd

here is paragraph2, adfasdfasdfsdfsdfasdfsd)

After I retrieve from database using stripslashes($note): it becomes:

here is paragraph1, fasfdasdfasdfasdfasdfasdfasdfasdfasdfasdfsdfsdfsadfasdfasdfsdfsd<br /><br /><br /><br /><br /><br />

here is paragraph2, adfasdfasdfsdfsdfasdfsd)

    Hello.
    Here is a very good article about slashes problem.
    Magic Quotes and Add Slashes in PHP

    I learnt what slashes is about, by reading article.
    🙂

    By the way, we can find good tutorials about most anything,
    if we know howto search with http://www.google.com/
    or by searching at http://php.net (has very good search utility!)
    That's the way I do it. To increase my knowledge.
    Also it is not forbidden to search this forum of phpbuilder.com
    Most problems has been covered several times before. I am sure.
    🙂

      Thank christ for that article. I see people using stripslashes after pulling data from a database all the time and it gets really annoying having to repeat the same bit of info to people. Even some quite advanced coders still think you have to do it.

      I might wakk that in my sig as a signpost for others, cheers dude.

        Originally posted by rvpals
        I have a form which allow user to enter a description or note. It's a textarea called note.

        My problem is that when I test enter some note, if I manually press enter to separate paragraph. After I insert into database, extra <br> is added in where I put in the line break so makes my paragraph separate by two line breaks instead of one I manually put in.

        Is there a way to do this without adding extra line breaks? Thanks a lot.

        Here is the code I used to insert note to database:
        $note = addslashes(trim($textarea));

        Here is the code I used to display note:
        $textarea = stripslashes($note);


        (For example:

        here is paragraph1, fasfdasdfasdfasdfasdfasdfasdfasdfasdfasdfsdfsdfsadfasdfasdfsdfsd

        here is paragraph2, adfasdfasdfsdfsdfasdfsd)


        After I retrieve from database using stripslashes($note): it becomes:

        here is paragraph1, fasfdasdfasdfasdfasdfasdfasdfasdfasdfasdfsdfsdfsadfasdfasdfsdfsd<br /><br /><br /><br /><br /><br />

        here is paragraph2, adfasdfasdfsdfsdfasdfsd)

        Thanks a lot for sharing the article. Halojob. It really helped me out.

          It helped me too!
          Now I understand magic quotes and add/strip slashes better, for my scripts.
          🙂

            Write a Reply...