Jump to content

display paragraph of text save to database through textarea


orange08

Recommended Posts

hi, i'm using textarea for user to key in their paragraph of text, then save those paragraphs to database. now, i'm having problem to display those text in correct alignment with simple echo command...

 

for example: i saved three paragraphs of text into database...but, when i display them in a table with this code

 

<table><tr>
<td><?php echo $myparagraph; ?></td>
</tr></table>

 

but, all the paragraphs will be displayed joined together, and the blank line will be ignored too...

so, i would like to know how can i solve this problem, please?

Link to comment
Share on other sites

but, got one problem, when my entry of text got single or double quote(', ")

then the output got backslash \ so how can i solve this?

 

Your input system is double escaping. As ken mentioned stripslashes will solve this. But if you post anything with slashes they tend to get removed. I would fix your database entry part as you are either addslashes to the data (which is wrong btw) or you are mysql_real_escape_string (which is what you should use) but while Magic Quotes are turned on, which would cause a double escape as well. If Magic Quotes are on I would suggest turning them off and that should prevent the double escaping without any code modification. However, if you do use addslashes I would suggest using the mysql function instead, as it escapes just for the mysql DB and will catch items that addslashes will not.

Link to comment
Share on other sites

but, got one problem, when my entry of text got single or double quote(', ")

then the output got backslash \ so how can i solve this?

 

Your input system is double escaping. As ken mentioned stripslashes will solve this. But if you post anything with slashes they tend to get removed. I would fix your database entry part as you are either addslashes to the data (which is wrong btw) or you are mysql_real_escape_string (which is what you should use) but while Magic Quotes are turned on, which would cause a double escape as well. If Magic Quotes are on I would suggest turning them off and that should prevent the double escaping without any code modification. However, if you do use addslashes I would suggest using the mysql function instead, as it escapes just for the mysql DB and will catch items that addslashes will not.

 

i have read a few times your explanation, but not too sure whether i really get it or not. as your suggestion, i'll display my paragraph like this:

 

echo nl2br(stripslashes($row['myparagraph']));

 

but, as you have mentioned, when i post something with slashes, the slash will be removed. so, how can i solve this? is that you meant i can use mysql_real_escape_string when the entry is saved to database?

 

and how can i know whether Magic Quotes is turn on or off?

 

thanks!

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.