Jump to content

how to put line breaks in this php code that will store them in my PHP


computel

Recommended Posts

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?

 

I have reading and reading for 2 days and can't figure out what I need to change.

 

Thanks

 

 

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");

?> 

 

Link to comment
Share on other sites

It stores the line breaks, HTML just does not convert them to <br /> tags, which is what is required for them to show up (that or encase the text in a <pre> tag).  When you pull the data out and get ready to display it, run nl2br on the data and it should convert the line breaks to the HTML <br /> tag.

 

I would not store the data with the html <br /> tags, keep it as line breaks in the database, just an FYI.

Link to comment
Share on other sites

how would I add the nl2br() where do I put the line in this code

 

here is the view.php file that grabs the code from the database and shows it

 

<?
require_once("conn.php");
require_once("includes.php");
require_once("access.php");

require_once("templates/HeaderTemplate.php");

if($_GET[cmd] == "cheat")
{
//show the current cheat
$q1 = "select * from games_content, games_catalog  where games_content.ContentID = '$_GET[id]' and games_content.ItemID = games_catalog.item_id ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1, MYSQL_ASSOC);

$date_added = date("M/d/Y", $a1[date_added]);
require_once("templates/ViewContentTemplate.php");
}
else
{

//get the game info
$q1 = "select * from games_catalog where item_id = '$_GET[content_id]' ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);

$content_title = $a1[item_name];

if(!empty($a1[order_link]))
{
	$buy_now = " - <a class=OrderLink href=\"$a1[order_link]\" target=\"_blank\">BUY NOW</a>";
}

if(!empty($a1[item_image]))
{
	$item_image = "<img src=\"image.php?image_id=$a1[item_id]&w=150&h=150\" border=1 width=150 height=150>";
}

//get the review template as a string
$tpl = file("templates/ReviewsList.php");
$tpl = implode("", $tpl);

if(empty($_GET[start]))
{
	$start = '0';
}
else
{
	$start = $_GET[start];
}

$ByPage = '10';

$i = $start;

//get the reviews
$q2 = "select * from games_content where ContentType = 'review' and ItemID = '$_GET[content_id]' limit $start, $ByPage ";
$r2 = mysql_query($q2) or die(mysql_error());
while($a2 = mysql_fetch_array($r2))
{
	$i = $i + 1;
	$title = $a2[ContentTitle];
	$review = $a2[ContentText];
	$date_added = date("M/d/Y", $a2[date_added]);
	$rating = stars_rating($a2[rating]);

	$tpl_variables = array("{ReviewNumber}", "{ReviewTitle}", "{ReviewText}", "{DateAdded}", "{rating}");
	$tpl_values = array($i, $title, $review, $date_added, $rating);

	$final_tpl .= "<tr>\n\t<td>\n\t\t";
	$final_tpl .= str_replace($tpl_variables, $tpl_values, $tpl);
	$final_tpl .= "</td>\n</tr>\n\n";
}

//navigation - Prev/Next
$qnav = "select count(*) from games_content where ContentType = 'review' and ItemID = '$_GET[content_id]' ";
$rnav = mysql_query($qnav) or die(mysql_error());
$anav = mysql_fetch_array($rnav);

$rows = $anav[0];

$new_start = $start + $ByPage;
$back = $start - $ByPage;

if($rows > $new_start)
{
	$next_x = $rows - ($start + $ByPage);
	$next = "<a href=\"view.php?cmd=review&id=$_GET[id]&content_id=$_GET[content_id]&start=$new_start\" class=BlackLink>Next $next_x</a>";
}

if($start > '0')
{
	$previous = "<a href=\"view.php?cmd=review&id=$_GET[id]&content_id=$_GET[content_id]&start=$back\" class=BlackLink>Previous 10</a>";
}

require_once("templates/ViewReviewsTemplate.php");
}




require_once("templates/FooterTemplate.php");

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.