Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving user formatting to my database?

Status
Not open for further replies.

kelani

MIS
Nov 29, 2000
44
US
I have a site where i want people to be able to upload their own poetry into a database. All I need is for their input to be sved as is, for example

This is a poem
I am happy
Notice how each line has a <br>


If thy type this into a form, it all comes out as one long string. I don't trust their intelligene to insert a <br> after every line. How can I automatically have this information displayed as typed?

TIA

Kelani
 
Code:
<cfset poem=replace(poem, &quot;#chr(13)##chr(10)#&quot;, &quot;<br>&quot;, &quot;all&quot;)>
should do the trick...
 
So, if the form field is data, I just type

<cfset data=replace(data, &quot;#chr(13)##chr(10)#&quot;, &quot;<br>&quot;, &quot;all&quot;)>


Thanks so much. You are the man
 
You got it...:) Since HTML doesn't &quot;show&quot; line breaks, you have to turn them into HTML coded <br>'s...
 
Hmm, where exactly in the query should this go?

<cfset data=replace(data, &quot;#chr(13)##chr(10)#&quot;, &quot;<br>&quot;, &quot;all&quot;)>

<cfquery name=&quot;db_insert&quot; datasource=&quot;dbname&quot; dbtype=&quot;ODBC&quot; username=&quot;user&quot; password=&quot;pswd&quot; dbserver=&quot;localhost&quot; dbname=&quot;dbname&quot;>
INSERT INTO poetry (id, info, cpr, data, email) VALUES ('#form.id#', '#form.info#', '#form.cpr#', '#form.data#', '#form.uname#')
</cfquery>

Insert works, but data is not being converted.
 
either
<cfset form.data= ...>
or
<cfquery ...> .... values(...., '#data#', ...)

i think it get confused about which &quot;data&quot; you set and or use
 
Yep. Your INSERT command is inserting the form.data, and not the variables.data that you set when you did the replace... DarkMan
 
God you guys are amazing. About one more question and I'll scurry away in fear of your vast knowledge :)
 
Ok masters, the last part of this mess.

Now that the poetry is formatted, I have it so that only users who have previously registerd can post. The poem adds, the data formats, but I want to add data from another table. I'm guessing I can use CFSET again, but again, all syntax I try gives me mad errors. Here we go.

<cfquery name=&quot;search_db&quot; datasource=&quot;db26401a&quot; username=&quot;username&quot; password=&quot;passwd&quot; dbserver=&quot;localhost&quot; dbname=&quot;dbname&quot;>
SELECT email, uname and pswd FROM users WHERE uname = '#form.uname#' AND pswd = '#form.pswd#'
</cfquery>

<CFIF #search_db.recordcount# is 1>

<cfset form.data=replace(data, &quot;#chr(13)##chr(10)#&quot;, &quot;<br>&quot;, &quot;all&quot;)>

<cfquery name=&quot;db_insert&quot; datasource=&quot;db26401a&quot; username=&quot;username&quot; password=&quot;passwd&quot; dbserver=&quot;localhost&quot; dbname=&quot;dbname&quot;>
INSERT INTO poetry (id, info, cpr, data, email) VALUES ('#form.id#', '#form.info#', '#form.cpr#', '#form.data#', '#form.name#')
</cfquery>

Now, how do I set 'name' and 'email' to be the variables from the search_db query?

Once again, I am in your debt

Kelani
 
> &quot;Now, how do I set 'name' and 'email' to be the variables from the search_db query?&quot;
<cfquery name=&quot;db_insert&quot; datasource=&quot;db26401a&quot; username=&quot;username&quot; password=&quot;passwd&quot; dbserver=&quot;localhost&quot; dbname=&quot;dbname&quot;>
INSERT INTO poetry (id, info, cpr, data, email) VALUES ('#form.id#', '#form.info#', '#form.cpr#', '#form.data#', '#search_db.uname#', '#search_db.email#')
</cfquery>

more generally, it's best (at least, it's clearer) to prefix variables with their scope (only 10 possible) :

query (queryname.variablename)
Local (Variables.variablename)
url param (URL.variablename)
form field (Form.variablename)
Client (Client.variablename)
Server (Server.variablename)
Session (Session.variablename)
Application (Application.variablename)
Cookie http (Cookie.variablename)
cgi environnment (CGI.variablename)





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top