Solved

asp saving text area into db

Posted on 2004-04-13
5
239 Views
Last Modified: 2012-05-04
Hello,

when I have the text from a textarea into a db I lose all the spaces on it, who can I save/retrieve and display in html using asp all the spaces?

thanks.
0
Comment
Question by:alain123
  • 3
5 Comments
 
LVL 12

Expert Comment

by:GoofyDawg
ID: 10819818
What database are you using? Normally, spaces are preserved unless you have some explicit filtering function that removes the spaces.
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 250 total points
ID: 10819823
A simple example here:

in your form, add:

<textarea name="aboutus" cols="50" rows="8"></textarea>

then in your process page:

<%
      response.expires = 0
      response.expiresabsolute = Now() - 1
      response.addHeader "pragma","no-cache"
      response.addHeader "cache-control","private"
      Response.CacheControl = "no-cache"

      on error goto 0
      
      set conn=server.CreateObject("adodb.connection")
      conn.Open "Provider=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("db.mdb")
      
      aboutus = Replace(Replace(Request("aboutus"),"'","''"), VbCrlf, "<br>")
      
      set rs = Server.CreateObject("ADODB.Recordset")
      SQLStr = "Update Setting Set " & _
                   "aboutus = '" & aboutus & "' "
      conn.execute SQLStr
      
      Conn.Close
      Set Rs = Nothing
      Set Conn = Nothing
%>

To display in HTML, you may need to display it like:

<%=Replace("" & Rs("aboutus"),"<br>",VbCrlf)%>

(in the case you know how to establish a connection using ADO)

Hope this helps
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10819835
>>when I have the text from a textarea into a db I lose all the spaces on it
Just curious if you entering your data with spaces like " " , if it's you may lose all your space when displayed in HTML, as HTML nature treats empty spaces as Empty , like below both are same when displayed in HTML:

Hello World<br>
Hello    World<br>

So the only way to 'retain' the spaces is using &nbsp; to replace the spaces.

so, you can try like:

aboutus = Replace(Replace(Replace(Request("aboutus"),"'","''"), VbCrlf, "<br>")," ","&nbsp;")

or

aboutus = Replace(Replace(Request("aboutus"),"'","''")," ","&nbsp;")

that's depends on your requirement..

regards

0
 
LVL 1

Author Comment

by:alain123
ID: 10820030
thank you!
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10820162
You're welcome, glad could make helps ;-) cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now