Jump to content

[SOLVED] News posting


velocite

Recommended Posts

Ive been writing a CMS, for sometime, learning as I'm going.

Main problem is this:

 

When i submit a news article, for example i write this in the box:

blah blah

blah

blah

 

once i display the news article is displays

blah blahblahblah

 

This is my post script

 

<?php
//Setting variable for the input values
$title_input = $_POST['title'];
$body_input = $_POST['bodytext'];
$date = date(Ymd);

//Including neccessary files to connect to database
    require( '../connect.php');
    require( '../config/config.php');
    
    if (!isset($_POST['title']))
    {
    	header('location:../addnews.php');
    }
    if (!isset($_POST['bodytext']))
    {
    	header('location:../addnews.php');
    }
    
    //Selecting the Database
mysql_select_db('test', $dbconnect);
//Add the inputted content into the database
mysql_query
(
$addnews = "INSERT INTO news (news_title, news_body, news_author, news_date)
VALUES ('$title_input', '$body_input', 'author', '$date')"
);

//If statement about displaying error message
if (!$addnews)
{
	$_SESSION['texterror'] = die('Adding the news failed ' . mysql_error());
	header('Location: ../addnews.php');
}
else
{
	$_SESSION['textsuccess'] = '<font color=green>Adding the news was successful</font><br /><br />';
	header('Location: ../addnews.php');
}


?>

Link to comment
https://forums.phpfreaks.com/topic/102277-solved-news-posting/
Share on other sites

Okay, the reason for this is that when you create a new line inside the text box, that is a newline character (\n). When you output something to a browser, it is not new line characters which create a new line, but break line tags (<br >)

 

The fix for this: On the output of this data, apply the nl2br() function. It's generally considered better practice to store the data in its raw form, and add in thinks like the <br > tags on the output of the data.

Link to comment
https://forums.phpfreaks.com/topic/102277-solved-news-posting/#findComment-523708
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.