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 13 of 13
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replace Enter with Space in Database

    Hi there...I have a pop-up window that passes a note to the main page.The note has enter or return in it like this:
    Line1
    Line2
    Line3

    However it is saved in databse(sql) as Line1 only, and gives me error Unterminated string on the asp page. When I go and hit delete after Line1 in the database, it then displays the whole string.

    Is there a way I can replace the enter or return with space...before displaying it??

    I have tried Test= Replace(Test,"\n","-") on the asp page but that doesn't work...do you think I should do something before it saves into the DB, any clues???

    Thanks!!!
    Last edited by terp_in_umcp; 04-03-2007 at 09:24 PM.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Turn off wrapping in the textarea and it won't save the carriage returns.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How do I turn off wrapping in the textarea?

    Thanks!

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I think you'd need this setting. Turning off wrapping still sends newlines.
    Code:
    <textarea wrap="virtual"></textarea>
    wrap="off" provides no wrapping. Unless your readers hit <ENTER>, the text they type in will scroll along on one long line. The text will be sent to the server as one long line unless the reader hits the carriage return key.

    wrap="virtual" wraps the text within the space of the text box, but sends it to the server as one long line, as if no wrapping occurred.

    wrap="physical" wraps the text within the text box, and sends it to the server exactly as the reader sees it in the text box.

  • #5
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow thats good to know...I will try tht and see how it works....

    I am pretty sure though tht the people who will be using this will hit enter while entering the note...So I was trying to do '"& Replace(Request("Comment"),"\n", "") &"' in the insert statement but thats not working....maybe I need to replace \n with something else...any clues???

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Can't help you with that I'm afraid, as I'm not too clued up on asp. Don't see why it shouldn't work

  • #7
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry...I tried wrap="virtual" and that dint work...neither did wrap="physical" and wrap="off"...I guess the problem is still that the data is being saved with the enter, which is totally messing it up.....so I need a way to save it into the database by removing the enter...

    Thanks for your feedback though Nightfire...that was informative

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    This any use for you?
    Code:
    strComent=replace(request.form("comment"), vbcrlf, "")

  • #9
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Thanks Thanks Night...that totally works...

    So before my sql Insert, I do

    strComent=replace(request("Comment"), vbcrlf, "")

    and in my insert statement i do '"&strComent&"'

    Thanks again, that works

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Don't thank me, thank google lol

  • #11
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Depending on your database, you will also need to remove any and all single quotes as they screw up your SQL statements.

    You can do this instead of creating another variable (although variables are the best way to go):

    Code:
    INSERT INTO testTable (Textarea) VALUES ('" & replace(replace(request("Comment"),vbCrLf,""),"'","\'") & "')
    
    OR 
    
    INSERT INTO testTable (Textarea) VALUES ('" & replace(replace(request("Comment"),vbCrLf,"<BR>"),"'","''") & "')
    
    OR With Variables
    
    strComment = replace(request("Comment"),vbCrLf,"")
    strComment = replace(strComment,"'","\'")
    
    INSERT INTO testTable (Textarea) VALUES ('" & strComment & "')

  • #12
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a bunch Daemon...thats indeed helpful...pretty neat huh

  • #13
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would keep the linebreaks in the database.
    I'm not sure what SQL Query you were using, but vbCRLF will not break an insert.


    If outputting to a textarea or preformmated text or textfile then you still have the line breaks in place.

    Use replace when outputting to HTML
    Code:
    Replace(rs("comment"),vbCrlf,"<br />")


  •  

    Posting Permissions

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