Is it possible to store <br> in the database, if yes how to filter the text but skip the line break <br> .

How to do it right?

 if(isset($_POST['sumbit'])){ $name = $_POST['name']; $text = $_POST['text']; $text_br = nl2br($text); $date_pub = time(); $data = "INSERT INTO blog (id, name, text, data_pub) VALUES (NULL, '$name', '$text_br', '$date_pub' ) "; } <?php if (mysql_query($data) == true): ?> <div class="result_edit">Информация успешно изменена !!</div > <?php else: ?> <div class="result_eror">Увы, но информация не изменена !!</div > <?php endif; ?> 

Closed due to the fact that the essence of the issue is incomprehensible by the participants aleksandr barakin , MAXOPKA , Vladimir Glinskikh , tutankhamun , Dmitriy Simushev Aug 28 '15 at 9:47 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    How do you save text to base? Add the code to the question. - Visman
  • Sorry, maybe I asked the wrong question, I changed the question and added the code. - user186631 pm
  • one
    You have no data in this code in the database. - Visman
  • @Visman: sort of added. - Nick Volynkin

3 answers 3

  1. The mysql_* functions mysql_* outdated! They should not be used. Use the functions mysqli_* to work with the database.
  2. All incoming data from the user should be checked / processed. Otherwise, you are waiting for SQL injection .

    2.1 Expected integers strictly reduce to integers

     $number_int = (int)$_POST['number']; 

    2.2 Process string data before writing to the database through the function mysqli_real_escape_string () (read the link about Security: the default character set )

     $str = mysqli_real_escape_string($db_link, $_POST['text']); 
  • one
    Yes, you already throw out mysqli. It is not necessary to go to it, but to PDO. - etki
  • @Etki, write your answer;) - Visman

Need to learn HTML.
Because the database has nothing to do with the translation of strings.

But in HTML, the translation of the lines is not really saved.

In the simplest case, to convert line breaks into corresponding HTML tags, PHP has a function nl2br ().

  • I changed the question and added the code. - user186631

Add html code to the database. Thus, you will be saved as text and <br/> , and <p/> , etc.

  • Gentlemen minus, explain why in the database should not save html code? - Shilgen
  • Exactly! Please explain. And if you don’t like my answer, offer your own - deleted_acc pm
  • @Shilgen: perhaps because this answer does not provide a solution itself. How to add, what tools? - Nick Volynkin
  • @NickVolynkin I appreciate your inability to read (re-read my first comment), the answer is suitable for the first edition of the question, stackoverflow is created for help and not for doing someone else's work (I'm talking about your questions "How ...?") - Shilgen
  • @Shilgen: the downsides are not from me, I’m just suggesting you an idea why there might be cons. - Nick Volynkin