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