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
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
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
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.