Jump to content

sql doesnt save enter which i entered in a textarea


lukelee

Recommended Posts

I am making a simple cms, i enter the text in a textarea,then save into sql something like:

 

test123

test456

 

but it display the contents in one line, like:

 

test123test456

 

does anyone know how to make sql save the 'enter'? thanks

 

here is my codes:

<form name="service" method="post" action="service_update.php">
        <textarea name="content"></textarea>      
        <input type="submit" name="submit" id="submit" value="Submit" />
</form>

 

<?php
session_start();
require_once('db.php');
$content = $_POST["content"];
$result=mysql_query("UPDATE content SET content='$content' WHERE id='6'");
?>

I have done half of it:

 

<?php

$query = mysql_query("SELECT content FROM content Where id='6'");

while($row = mysql_fetch_array($query)) { 

$content = $row['content'];

function format_html($content)

{

  $content = "<p>" . str_replace("\r\n", "<br/>", $content) . "";

  $content = "" . str_replace("<br/><br/>", "</p><p>", $content) . "";

  return "" . str_replace("<br/><li>", "<li>", $content) . "";

}

echo  format_html("$content"); }?>

 

 

it works on 'enter' change a new line, but still not work if i want to have more spaces between words.like:

 

123        456

it only display 1 space:

123 456

 

does anyone know what code do i have to add?

This has nothing to do with PHP, but with HTML. HTML will trim all your spaces to one, and will ignore all line breaks. (Well...not HTML, but browser parsing it actually)

 

 

 

You have to put your content within <pre> </pre> tags to keep these whitespace characters displayed.

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.