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!

Know why this is giving me a syntax error? 1

Status
Not open for further replies.

bobbyr

Programmer
Nov 30, 2000
66
US
This is the form:

<form action=&quot;updatecontent.cfm&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;HowMany&quot; value=&quot;<cfoutput>#getcontent.recordcount#</cfoutput>&quot;>
<cfoutput query=&quot;getcontent&quot;>
<input type=&quot;hidden&quot; name=&quot;ContentId#CurrentRow#&quot; value=&quot;#ContentId#&quot;>
<b>Content:</b><br>
<textarea cols=&quot;50&quot; rows=&quot;5&quot; name=&quot;ContentText#CurrentRow#&quot;>#ContentText#</textarea>
</cfoutput>
<br><br>
<div align=&quot;center&quot;><input type=&quot;submit&quot; value=&quot;Update Content&quot;></div>
</form>

And here is the update page:

<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;#form.HowMany#&quot;>
<cfset ContentText = Replace(&quot;form.ContentText&quot; & i, &quot;#chr(13)##chr(10)#&quot;, &quot;<br>&quot; , &quot;all&quot;)>
<cfset ContentId = &quot;form.ContentId&quot; & i>
<cfquery name=&quot;updatecontent&quot; datasource=&quot;icebulls&quot; dbtype=&quot;ODBC&quot;>
UPDATE Content
Set ContentText = '#Evaluate(ContentText)#' WHERE ContentId = #Evaluate(ContentId)#
</cfquery>
</cfloop>

The only thing I can think of is that I messed up the syntax in the <cfset> for ContentText due to the replace AND counter... Any insight??
 
some info on the error : what does it say ? where is it happening ?
 
I think the error will be on the line:

<cfset ContentText = Replace(&quot;form.ContentText&quot; & i, &quot;#chr(13)##chr(10)#&quot;, &quot;<br>&quot; , &quot;all&quot;)>

(and repeated on the next line due to the &quot;form.ContentText&quot; & i part.

I don't think you can loop through the controls on the form like this. You may have to hard code each one - use the IsMissing keyword (I think, but may be getting mixed up with VB!!) to check for the existence of the control,... (if it is not IsMissing, then it is something similar)

Simon
 
in coldfusion : isdefined ! (for a variable name)
 
I only had to change one(1) thing to get this to work.
I placed single quotes around the variable in the WHERE clause.
Oracle griped until I did that.

What was your error?

I like your technique of creating the hidden fields and dynamically populating the name based upon the currentrow. In fact, I didn't know #currentrow# existed. Thanks.

-Paul
 
I learned the hidden field/counter trick while coding ASP. I finally got through the first part of the error, but I'm not sure what the problem was. Now, the problem I'm having is that the &quot;ContentText&quot; has apostrophe's (') in them and I'm getting that goofy error. I've tried the Replace(ContentText, &quot;'&quot;, &quot;''&quot;, &quot;All&quot;) to no avail. Here's my current code:

<cfloop index=&quot;i&quot; from=&quot;1&quot; to=&quot;#form.HowMany#&quot;>
<cfset ContentId=&quot;form.ContentId&quot; & i>
<cfset ContentText = Replace(&quot;form.contenttext&quot; & i,&quot;#chr(13)##chr(10)#&quot;,&quot;<br>&quot;,&quot;all&quot;)>
<cfquery name=&quot;updatecontent&quot; datasource=&quot;icebulls&quot; dbtype=&quot;ODBC&quot;>
UPDATE Content_Field Set ContentText = '#Evaluate(ContentText)#' WHERE ContentId = #Evaluate(ContentId)#
</cfquery>
</cfloop>

This is working great.... as long as there's no apostrophe's in the text. So what I've been trying to figure out is how to get another Replace() going, or to incorporate PreserveSingleQuotes. The problem is that I'm already doing an Evaluate() on the ContentText.
 
can't you '#Evaluate(#PreserveSingleQuotes(contentText)#)#' in the query ???
if this doesn't work maybe you could first replace (BEFORE the query) then evaluate (in within the query). Oh ! and replacing ' with '' surely doesn't work ! you have to use either &quot;chr(??)&quot; (ask someone else for the exact number !) or &quot;`&quot; for example
replace(ContentText, &quot;'&quot;, &quot;`&quot;, &quot;All&quot;)

 
Using Preservesinglequotes is the right answer. I was running into the same problem. I tried replace and rereplace, (replacing with quotes or 2 apostrophes)but that makes the situation worse when there is a single quote.
e.g. paul's becomes paul&quot;s or paul''s.

 
the only other solution (than preservesinglequotes) is to replace with ` but it looks awfull ... we would read Paul`s ;-)
 
OK!! It's working... iza's trick did the job! <cfset ContentText = Replace(ContentText, &quot;'&quot;, &quot;#chr(39)#&quot;, &quot;All&quot;)>

Thank you to all for your help. I can finally get some sleep at night :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top