Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Line failing to break

    Does anyone know why I am not getting lines brakes when using \n when inserting the following into a MySQL field?

    '".date(DATE_RFC822)."\nWRITING ORDER TO DATABASE\n'

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,449
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    Works for me. I did it just with command line, but that shouldn't matter.
    Code:
    mysql> insert into flash values('here is some text\n3/12/2012\nand some more test');
    Query OK, 1 row affected (0.02 sec)
    
    mysql> select * from flash;
    +------------------------------------------------+
    | s                                              |
    +------------------------------------------------+
    | here is some text
    3/12/2012
    and some more test |
    +------------------------------------------------+
    1 row in set (0.00 sec)
    OH! I think maybe I do know!!!

    \n is a newline character in PHP, too! So maybe you need to escape it so it's not treated as such by PHP?

    That is ...." . date(DATE_RFC822 . "\\nWRITING ORDER TO DATEBASE\\n" ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Hi Old Pedant.

    I tried braking out with the \\n but it didn't have any effect.
    I will continue my investigation and let you know when I find a solution so you can learn it to.

    Speak to you soon... I hope. lol
    Last edited by FlashDance; 11-06-2011 at 02:53 PM.

  • #4
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    OK, I am back on PHP again and tried this, but fail.

    PHP Code:
    $query "INSERT INTO orders (events) VALUES ('".date(DATE_RFC822)."\nWRITING ORDER TO DATABASE\n')"
    Last edited by FlashDance; 11-06-2011 at 02:53 PM.

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    So, it was working all along. I only noticed now when I checked MySQL from terminal. I got it working the way I needed it using the HTML element <PRE>

    Solved.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •