Jump to content

insert/display problem


pouncer

Recommended Posts

$Desc = mysql_escape_string($_POST['txt_Description']);

 

thats my description text box, which is what i insert into my sql table

 

say if i enter my description like this:

 

hello, these are my favourite dvd's
!!!!!

 

When i query my database to display it, it gives me:

hello, these are my favourite dvd's!!!!!

the exclamation marks should be on a new line right!???

 

$description = stripslashes($row['description']);

 

thats how im getting it!

 

echo $description;

Link to comment
https://forums.phpfreaks.com/topic/40363-insertdisplay-problem/
Share on other sites

Do not apply the nl2br() function when you insert the data into the database, only use it when you're displaying the data. Also you should be using the mysql_real_escape_string() function.

 

One caveat, I have heard that the mysql_real_escape_string() function will convert the newline character "\n" to a plain string '\n' which the nl2br() function will not find. If this causes you problems, use something like this:

<?php
echo '<td align=center bgcolor=#F5F5FF>' . nl2br(str_replace('\n',"\n",$description)) . '</td>';
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/40363-insertdisplay-problem/#findComment-195347
Share on other sites

kenrbnsn

 

here you are jus replacing \n with \n

 

<?php
echo '<td align=center bgcolor=#F5F5FF>' . nl2br(str_replace('\n',"\n",$description)) . '</td>';
?>

 

use this

it will replace '\n' to "\n"

<?php
echo '<td align=center bgcolor=#F5F5FF>' . nl2br(str_replace("'\n'",'"\n"',$description)) . '</td>';
?>

Link to comment
https://forums.phpfreaks.com/topic/40363-insertdisplay-problem/#findComment-196741
Share on other sites

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.