velocite Posted April 22, 2008 Share Posted April 22, 2008 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'); } ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 22, 2008 Share Posted April 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
velocite Posted April 22, 2008 Author Share Posted April 22, 2008 So when i output i apply that function like this? <?php $text = nl2br($row[$id]['body']); ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 22, 2008 Share Posted April 22, 2008 Thats it. Or you can do it when you echo, up to you: echo nl2br($var); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.