• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Urgent: insert doesnt display properly????

Ok, I have a form on a webpage, that collects data and sends it to an SQL query that inserts into the appropriate field in my MS Access DB, say if i input text in my form just like the way i have it below to actually display like that when i call it to a web page, below is what it looks like when i put it into the form, and after is what it looks like when i call it back from the database in another html page, by the way im using coldfusion and SQL to call the text from the database:


//What text looks like when i have wrote it into form, then submitted to DB:

Friendship Between Women:
A woman didn't come home one night. The next day she told her husband
That she had slept over at afriend's house. The man called his wife's 10
Best friends.
None of them knew about it.


Friendship Between Men:


A man didn't come home one night. The next day he told his wife that
He had slept over at friend's house. The woman called her husband's 10 best
Friend's.
Eight of them confirmed that he had slept over, and two
claimed that he was still there.



//What text looks like when i call it from the DB and display it to the screen:

A woman didn't come home one night. The next day she told her husband That she had slept over at afriend's house. The man called his wife's 10 Best friends. None of them knew about it. Friendship Between Men: A man didn't come home one night. The next day he told his wife that He had slept over at friend's house. The woman called her husband's 10 best Friend's. Eight of them confirmed that he had slept over, and two claimed that he was still there.


How do i get it to display the way i inputted it???

This is my SQL Code:

INSERT INTO editbook (editbook,userentry,user,[date])
VALUES
('#id#','#form.userentry#','#session.username2#','#DateFormat(Now(), "DD/MM/YYYY")#')

userentry is the field that the text gets inputted into.

Thanks,

Ian
0
Ianaldo
Asked:
Ianaldo
  • 3
2 Solutions
 
js_vaughanCommented:
Do something like this:

<cfset userText = form.userentry>
<cfset userText = ReplaceList(inputstream,"#chr(13)#,#chr(10)#","<br>")>
<cfset userText = Replace(result,'  ',' &nbsp;','ALL')>
<cfset userText  = Trim(preserveSingleQuotes(userText))>

INSERT INTO editbook (editbook,userentry,user,[date])
VALUES('#id#','#userText#','#session.username2#','#DateFormat(Now(), "DD/MM/YYYY")#')
0
 
IanaldoAuthor Commented:
Actually i just checked my DB, it inputs fine into the DB, but displaying it back to the screen is the problem, it join all the sentences and paragraphs together, when i look at the DB its in the "before format" like i have above, but when i output that to the screen using CF, its in the "after format"!?!?

Thanks.
0
 
js_vaughanCommented:
You could then try using this on your output :

<cfset displayText = YOUR_DB_FIELD>
<cfset displayText = ReplaceList(displayText ,"#chr(13)#,#chr(10)#","<br>")>
<cfset displayText = Replace(displayText ,'  ',' &nbsp;','ALL')>

The important part that is working here is that browsers do not display line breaks and multiple spaces.  These always just convert into one space on screen.

Line 1 gets the value from your database
Line 2 converts line breaks into browser-friendly <br> tags
Line 3 converts multiple spaces into a space and the &nbsp; code... which in a browser will convert back out to a space on screen

( P.S. as a correction on my prior comment, change "inputstream" to "userText" )
0
 
js_vaughanCommented:
Oh ... one more thing ... the reason that I did it BEFORE hitting the database the first time is so that you dont have to run those 3 lines every single time the page is displayed to your visitors... you only have to run it once before it goes in (and do the reverse process if you have to output it back into a textarea for reformatting.)

Its just alot less work on the coldfusion server this way.  Just my 2 cents :-)
0
 
JeffHowdenCommented:
It's important, Ianaldo, to consider editability.  If that's important *and* HTML markup will be disconcerting, confusing, etc. for the user(s) editing it, I'd suggest that the "expense" of dynamic markup similar to what js_vaughn suggests would be well worth it.  That decision out of the way, I'd like to recommend that you dynamically markup your text from the database in a more proper manner.  Simply stuffing a bunch of <br> tags wherever you find carriage return/linefeed combinations isn't semantically correct, is a pain in the ass to style via CSS, and isn't the best suited combination of tags for the job.  Rather, I'd suggest checking into the built-in function ParagraphFormat() if you're documents target doctype is HTML 4.01 or older or a user-defined function available at CFLib.org called XHTMLParagraphFormat() if your document's target doctype is HTML 4.01, XHTML or even some variety of XML.

http://www.cflib.org/udf.cfm?ID=419
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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