I'm working on a simple messaging web. The process is simple, I enter the text with line breaks and it will be saved on the database and display it in another div. Everything was fine until I used mysqli_real_escape_string()
which removed all the line breaks and display whole text in a single line
$text = $_POST['new_text'];
$vaild_text = mysqli_real_escape_string($con,trim($text));
$vaild_text = strip_tags($vaild_text);
$breaked_text = nl2br($vaild_text);
$command = "INSERT INTO textTable (text_col)VALUES ('$breaked_text')";
$query = mysqli_query($con,$command);
If I remove mysqli_real_escape_string()
everything
works very well but for the matter of security I Can't
I even changed the nl2br()
position and put it after and before mysqli_real_escape_string()
but it didn't work!