View Full Version : Replace Enter with Space in Database
04-03-2007, 08:21 PM
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:
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???
04-03-2007, 08:44 PM
Turn off wrapping in the textarea and it won't save the carriage returns.
04-03-2007, 08:47 PM
How do I turn off wrapping in the textarea?
04-03-2007, 08:52 PM
I think you'd need this setting. Turning off wrapping still sends newlines.
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.
04-03-2007, 08:58 PM
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???
04-03-2007, 09:02 PM
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
04-03-2007, 09:08 PM
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:)
04-03-2007, 09:17 PM
This any use for you?
strComent=replace(request.form("comment"), vbcrlf, "")
04-03-2007, 09:44 PM
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:)
04-03-2007, 09:47 PM
Don't thank me, thank google ;) lol
04-04-2007, 01:15 PM
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):
INSERT INTO testTable (Textarea) VALUES ('" & replace(replace(request("Comment"),vbCrLf,""),"'","\'") & "')
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 & "')
04-04-2007, 02:47 PM
Thanks a bunch Daemon...thats indeed helpful...pretty neat huh:)
04-18-2007, 02:43 PM
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
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.