views:

231

answers:

4

Quick and simple (I hope) question; If a user inputs new lines in a text field, ie:

43 Dennis

Beeston

How can I save the new line rather than have it transferred to the mysql server as one line?!

I am using PHP and mysql.

Many thanks

A: 

MySQL should preserve the newline - could it be your output (or your mysql gui) that isn't displaying it?

adam
+1  A: 

To save the newlines in the database, take a look at mysql_real_escape_string

If you want your newlines displayed as breaks on the page when you display the records, use nl2br.

AJ
using <?php echo "$propertyAddr" ?> I simply get: 10 Burrows Crescent\r\nBeeston\r\nNottingham\r\n
nicky
@nicky, updated my answer.
AJ
A: 

When you output the field from the database to an html document, either use <pre> or nl2br() (or a <textarea>).

Anax
A: 

very neat, but will this saves javascript as well too? will this cause CSS attack?

tq

improve search engine rankings