Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

asp saving text area into db

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
alain123
Asked:
alain123
  • 3
1 Solution
 
GoofyDawgCommented:
What database are you using? Normally, spaces are preserved unless you have some explicit filtering function that removes the spaces.
0
 
Ryan ChongCommented:
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
 
Ryan ChongCommented:
>>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
 
alain123Author Commented:
thank you!
0
 
Ryan ChongCommented:
You're welcome, glad could make helps ;-) cheers
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now