Line Breaks in php to mywsl

I have a script that takes in information in a text box and it stores it in a mysql database but it doesn’t store the line breaks. So the text is displayed back it’s all jammed together and hard to read.

How do I get it to store all the line breaks?

Here is the script


<? require_once("conn.php"); require_once("includes.php"); require_once("access.php"); if(isset($_POST[s1])) { if($_POST[content_type] == "cheat") { $ItemID = $_POST[item_id_1]; $ContentTitle = strip_trim($_POST[cheat_title]); $ContentText = strip_trim($_POST[cheat_text]); } else { $ItemID = $_POST[item_id_2]; $ContentTitle = strip_trim($_POST[review_title]); $ContentText = strip_trim($_POST[review_text]); $rating = $_POST[rating]; } $q1 = "insert into games_content set ContentType = '".mysql_real_escape_string($_POST[content_type])."', ItemID = '".mysql_real_escape_string($ItemID)."', ContentTitle = '".mysql_real_escape_string($ContentTitle)."', ContentText = '".mysql_real_escape_string($ContentText)."', rating = '".mysql_real_escape_string($rating)."', date_added = '".mysql_real_escape_string($t)."', user_id = '".mysql_real_escape_string($_SESSION[MemberID])."' "; mysql_query($q1) or die(mysql_error()); $last = mysql_insert_id(); header("location:view.php?cmd=$_POST[content_type]&id=$last&content_id=$ItemID"); exit(); } if($_POST[content_type] == "cheat" || empty($_POST[content_type])) { $checked1 = "checked"; } elseif($_POST[content_type] == "review") { $checked2 = "checked"; } require_once("templates/HeaderTemplate.php"); require_once("templates/AddReviewTemplate.php"); require_once("templates/FooterTemplate.php"); ?>


in the function strip_trim it will remove the line spaces so don’t use that function on the text

so just remove them from the from this php file?


yes use:

$ContentText = $_POST[cheat_text];

since your escaping it in the query.

I tried that just now and it doesn’t work.

I don’t think the code is storing the line breaks in the mysql database.


you could try the function nl2br :

apply it when showing the text

echo nl2br($ContentText);

figured it out. I had to add the nl2br to another php file and it worked.

there is a view.php file and I added this

$review = nl2br($a2[ContentText]);

Thanks for your help.

excellent, your welcome :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service