tags:

views:

94

answers:

2

I've been building a db input form. There are three fields for notes. They were all build at the same time. They have the same logic & class system - but one of them is returning with escape marks when I update the record (e.g.) i enter

1
2
3

and the updated record returns

1\r\n2\r\n3

I'm confused as the other return the text as formatted. Can you sugggest why this is happening?

A: 

As it is, your question lacks a lot of crucial information. Obviously, if everything is done identically, the data will be the same as well. Additionally, you probably don't mean that there are escape marks in your data (or do you?). In that case, you must have explicitly called a function to convert line breaks into a string containing the characters '\' and 'n'.

Lacking any code, I assume that you display your data differently; once using a normal echo and once using something like var_dump.

Konrad Rudolph
+1  A: 

As Konrad suggested your question lacks clarity. Are they both on the same page? If not, do both pages have the same DOCTYPE?

The simplest solution to this is to handle it regardless, addslashes (or mysql_real_escape_string) for INSERTs and UPDATEs and stripslashes for SELECTs.

The other scenario you have to handle is a POST to a page that has errors (e.g repopulated with post values). You must make sure that the POST value is the 'stripped' version of the slashes else you will double up on the addslashes; so only addslashes when all your post validation and verification has been completed.

Jay