Keep form formatting when adding to database

Hi I use a form to submit my data(a discription in this case) via php. Is there a way I can keep for formatting, namely the paragraphs? when i print them back out of my database its taken the carriage returns out.

thanks for your time,

Darren.

Thanks for the reply. I’ve tried it but it doesnt do the job.

basicaly in the text area, when i press return for a newline can i somehow store the carriage return? i dont really want to be putting in <BR> or /n while im trying out a product description.

Thanks

i bet they’re still there :slight_smile:

html considers carriage returns as white space

You shouldn’t change the way you store the data in the database, but apply the nl2br function when you show the text.

The reason you should do this when displaying instead of when saving is that every time the user would save the description more <br/>'s would be added on each save (when using the “change before inserting” approach)

lol i did try that but must have been using it in another way

TY just the trick

apparently, there is a nl2br (new line to break) function

:wink:

been trying to do something like this but it doesnt work

$row[2] = ereg_replace(" “,”/n",$row[2]);

Rough outline


// connect to db
// assumption: some_table is empty (0 rows)
/* assumption. $_POST['description'] = "This is a\
test";
*/
$desc = mysql_real_escape_string($_POST['description']);
$sql = "INSERT INTO some_table(description) VALUES($desc)";
mysql_query($sql);
$sql = "SELECT * FROM some_table";
$row = mysql_fetch_assoc(mysql_query($sql));
echo nl2br($row['description']);
/* echoes
This is a<br />
test
*/

well does this mean I can do some sort of string replace before i show the product? and what code am i looking for carriage return?