Solved

asp saving text area into db

Posted on 2004-04-13
5
238 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

15 Experts available now in Live!

Get 1:1 Help Now