Hey everyone,
I was hoping somebody could maybe point me in the right direction here. I’ve made many many simple blogs and have never had this problem so I am totally stumped. Searches of the web and forums haven’t provided me with a solution yet so I was going to run this by yall and see what you think. I’m hoping it’s just something I’ve overlooked cause I’m out of ideas.
The issue is that when I make a post like:
<p>
This is the text of the post
</p>
It displays like this:
rnThis is the text of the postrn
For some reason the new line characters from my entry are being displayed. This is also true when I edit the entry. Instead of the textarea reading the new line characters and keeping my entry formatted properly it is all connected with no line breaks (which makes it inconvenient to edit as the entry becomes one endless line with “rn” where there should simply be a new line. Ill paste what It displays in the textarea in my edit script:
<p>rnThis is the text of the postrn</p>
I have no idea whats going on, like I said this has never happened to me before. Here is my code for the adding, viewing, and editing of the entry:
```php
public function add_blog($title, $body, $image_path) {
if(!empty($title) && !empty($body)) {
$blogTitle = trim(mysql_real_escape_string($title));
$blogBody = trim(mysql_real_escape_string($body));
if(!empty($image_path)) {
$image = trim(mysql_real_escape_string($image_path));
$q = "INSERT INTO blog (blog_id, blog_title, blog_body, blog_image, date_entered)
VALUES (0, '$blogTitle', '$blogBody', '$image', NOW())";
}else{
$q = "INSERT INTO blog (blog_id, blog_title, blog_body, date_entered)
VALUES (0, '$blogTitle', '$blogBody', NOW())";
}
$r = mysql_query($q);
if($r) {
$this->_messages[] = "<p>Your entry '" . stripslashes($blogTitle) . "' was successful.</p>";
}else{
$this->_messages[] = '<p class="error">Could not add your entry.</p>';
if(is_admin()) {
$this->_messages[] = '<p class="error">' . mysql_error() . '</p>';
}
}
}
} // END add_blog
public function edit_blog($id, $title, $body, $image_path) {
if(!empty($title) && !empty($body)) {
$blogTitle = trim(mysql_real_escape_string($title));
$blogBody = trim(mysql_real_escape_string($body));
if(!empty($image_path)) {
$image_path = trim(mysql_real_escape_string($image_path));
$q = "UPDATE blog SET blog_title='$blogTitle', blog_body='$blogBody',
blog_image='$image_path' WHERE blog_id=$id";
}else{
$q = "UPDATE blog SET blog_title='$blogTitle', blog_body='$blogBody'
WHERE blog_id=$id";
}
$r = mysql_query($q);
if($r) {
$this->_messages[] = "<p>Your entry '" . stripslashes($blogTitle) . "' was successfully updated.</p>";
}else{
$this->_messages[] = '<p class="error">Could not update your entry.</p>';
if($this->is_admin()) {
$this->_messages[] = '<p class="error">' . mysql_error() . '</p>';
}
}
}
} // END edit_blog
public function get_blog($id) {
if(is_numeric($id)) {
$q = "SELECT *, DATE_FORMAT(date_entered, '%M %D, %Y @ %r') AS dr FROM blog WHERE blog_id=$id";
$r = mysql_query($q);
if($r) {
$row = mysql_fetch_array($r);
$title = trim(stripslashes($row['blog_title']));
$text = trim(stripslashes($row['blog_body']));
$image = trim($row['blog_image']);
$date = trim($row['dr']);
// Create array of blog values to be returned
$entry = array('id' => $id, 'title' => $title, 'text' => $text,
'$image' => $image, 'date' => $date);
return $entry;
}else{
$this->_messages[] = "Could not access blog.";
return false;
}
}else{
$this->_messages[] = "Invalid blog ID.";
return false;
}
} // END get_blog
public function show_blog($id) {
// use get_blog to access content then display
if($entry = $this->get_blog($id)) {
echo '<center>';
if(!empty($entry['image'])) {
echo '<img height="250" src="' . $entry['image'] . '" />';
}
echo '<h1>' . $entry['title'] . '</h1>
' . $entry['date'] . '
</center>
<br />
' . $entry['text'] . '
<br />
<br />';
if($this->is_auth()) {
echo '<div style="clear:both; margin-top:10px; margin-bottom:10px;">
<center>
<a href="editBlog.php?blogID=' . $id . '" class="mainButton">Edit</a>
<a href="deleteBlog.php?blogID=' . $id . '" class="mainButton">Delete</a>
</center>
</div>
<div class="clr"> </div>';
}
}
} // END show_blog
If anyone see's what I'm doing wrong I would (and so would my brain!) greatly appreciate the insight. Thank you guys/gals.
P.S. If I messed up the code/highlight system on this post I apologize and will try to get it fixed right away.