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'");
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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.