Go Back   nV News Forums > Software Forums > Software Development

Newegg Daily Deals

Reply
 
Thread Tools
Old 07-23-07, 04:52 AM   #1
SoireeExtreme
Registered User
 
Join Date: Jul 2007
Posts: 5
Default Save coding to database

As the two posts below me, I'm saving a text area to the database but I'm saving it with coding such as html. the coding will save which is fine. But when I try to put the coding and text with some new lines just by hitting enter, it saves everything to the database but adds in the letters "rn" how can I get it to save with out those letters?

Its a bit annoying. But the only way I know to work around it right now is just to bunch everything together. Any help would be great. Thanks in advance.

My database "type" is "text"

If any info is needed please let me know.
SoireeExtreme is offline   Reply With Quote
Old 07-23-07, 12:31 PM   #2
fivefeet8
Ngemu Mod
 
Join Date: Jul 2003
Location: Fresno, CA
Posts: 1,886
Default Re: Save coding to database

Where and in which way does it save it with the "RN"? Is it random? I'm thinking it might be something with magic_quotes, but not too sure.
__________________
[i7 2600k @4.4ghertz][2x4 GB DDR3 1600][EVGA GTX570 1.280GB SC][EVGA GTX460 physx][Asrock Extreme7 Gen3 Z68][2xSeagate 160 Gb SATA HD raid0][Seagate 250 GB SATA2 HD][Sony Bravia 40' 1080p LCD HDTV][NEC 3520a DVD+-DLw][Windows 7 Ultimate x64][Rosewill 1000w]
fivefeet8 is offline   Reply With Quote
Old 07-23-07, 12:45 PM   #3
evilghost
Registered User
 
Join Date: Jul 2005
Posts: 3,606
Default Re: Save coding to database

I'm thinking it's \r\n

Carriage Return + Newline, because the text area is multi-line.

str_replace(); should work.
evilghost is offline   Reply With Quote
Old 07-23-07, 07:27 PM   #4
SoireeExtreme
Registered User
 
Join Date: Jul 2007
Posts: 5
Default Re: Save coding to database

Thanks for the help, but I do not understand the str_replace();. I was reading the php manual but that didn't help. I forgot to tell you that I am still fairly new to php and mysql both. So please bare with me. But to give a bit more info.

rn is exactly how it looks when I hit the enter key for a new blank line just like typing a document.

I use
PHP Code:
     print "Headline:<br><textarea name='headline' rows='1' cols='60'>$userstats3[headline]</textarea><br>";
as my text area

and I use
PHP Code:
    if(isset($_POST['submit']))
    {

    
$headline=$_POST['headline'];

      
$SQL = "update d_users set headline='$headline'where username='$userstats3[username]'";
      
mysql_query($SQL) or die("could not register");
      echo
"<center>Updated.";
to save it to the database.


And when I have everything print out onto another page it comes out like this...


rn = new line done by enter key

words words words.rnrnwords words.

so in the process of saving it is converted someone from a new line to the rn. This helps. Please explain to me how to fix this problem. Because as I said the manual doesn't help me. I'm more of a hands on person. In the mean time I'll keep trying to figure this out and let you know if I do.
SoireeExtreme is offline   Reply With Quote
Old 07-23-07, 07:42 PM   #5
evilghost
Registered User
 
Join Date: Jul 2005
Posts: 3,606
Default Re: Save coding to database

Two things, and I'm not being critical, but rather trying to be helpful.

1) From a security perspective, never, never trust user input. In this case you need to be sure to escape the mysql input or you'll end up with a fatal SQL injection vulnerability. Use the function mysql_real_escape_string();

2) \r\n are injected from multi-line text-area, because you're writing it out in another page you need to convert \r\n to a HTML <br> tag or use the <pre> HTML entity to have it properly treat \r\n.

What I think you should do:

Change:
Code:
$headline=$_POST['headline'];
To:
Code:
$headline=mysql_real_escape_string(str_replace("\r\n","<BR>",$_POST['headline']));
Understand I'm not being critical one bit but with respect to #1 I can't pound that into your head enough I'm always glad to help in any way I can, welcome to NVNews.
evilghost is offline   Reply With Quote
Old 07-23-07, 08:03 PM   #6
SoireeExtreme
Registered User
 
Join Date: Jul 2007
Posts: 5
Default Re: Save coding to database

I understand your being helpful. Reason why I came here is exactly for that. Help. Thanks for any help and tips you give and may give.

But... I changed my code as you suggested and I still end up with same problem as stated above.

I'm sure it'll hurt me in the long run. But instead of putting "\r\n" I took out the \\. When I did that it saved exactly as I wanted it to.

Is there another way to fix this? because as I said "\r\n" didn't work that way. And there are words out there that have rn together in them and this will affect those words only to create another problem for me. lol.
SoireeExtreme is offline   Reply With Quote
Old 07-23-07, 08:08 PM   #7
evilghost
Registered User
 
Join Date: Jul 2005
Posts: 3,606
Default Re: Save coding to database

You running PHP on Apache, on Linux or Win32?

\r\n seems to indicate Win32...
evilghost is offline   Reply With Quote
Old 07-23-07, 08:12 PM   #8
SoireeExtreme
Registered User
 
Join Date: Jul 2007
Posts: 5
Default Re: Save coding to database

I am using windows xp and yes php with apache. I have xampp.
SoireeExtreme is offline   Reply With Quote

Old 07-23-07, 08:15 PM   #9
evilghost
Registered User
 
Join Date: Jul 2005
Posts: 3,606
Default Re: Save coding to database

I honestly don't know why it's stripping \r\n and converting it to 'rn'.

It should properly escape \r\n and not treat it as 'rn' so I'm a little confused. It could be a PHP bug with respect to mysql interaction on Win32. See if you can Google and find an answer, I honestly don't know why it's happening.

Perhaps some other folks will chime in.
evilghost is offline   Reply With Quote
Old 07-23-07, 08:19 PM   #10
SoireeExtreme
Registered User
 
Join Date: Jul 2007
Posts: 5
Default Re: Save coding to database

Well thank you, I shall use google. But hey nothing is everything perfect. You did help me so I am better off then I was. If I find an answer I'll be sure to post it and let you know. Much appreciated. Thank you again.
SoireeExtreme is offline   Reply With Quote
Old 07-23-07, 08:23 PM   #11
evilghost
Registered User
 
Join Date: Jul 2005
Posts: 3,606
Default Re: Save coding to database

Glad to have been able to somewhat help... Stick around
evilghost is offline   Reply With Quote
Old 07-25-07, 07:52 AM   #12
ViN86
 
Join Date: Mar 2004
Posts: 15,486
Default Re: Save coding to database

remember that \ is the escape character in PHP, so when you want to use a character in a string like a quotation, you need to use \" - so maybe its escaping the \ character and displaying just "rn".

if this is the case, wouldnt it be "\\r\\n" ghost?

try...
Code:
$headline=mysql_real_escape_string(str_replace("\\r\\n","<BR>",$_POST['headline']));
ViN86 is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Verizon's shared data plans won't save solo users much money News Archived News Items 0 06-12-12 10:40 AM
League of Legends database hacked. Riot Games 'appreciate your immediate attentionā News Gaming Headlines 0 06-09-12 11:10 AM
NVISION: Create Games Without Any Coding Knowledge News Archived News Items 0 05-30-12 04:26 AM
Girls Impress FIRST Championship With Project That Could Save Lives (GeekDad Weekly R News Archived News Items 0 05-13-12 05:30 PM
Benchmark database? Necromancer NVIDIA Windows Graphics Drivers 1 08-25-02 10:15 AM

All times are GMT -5. The time now is 01:03 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©1998 - 2014, nV News.