I want create a log file. I tried but its show me an error. Can anyone help? I show my full code here:
http://pastebin.com/SxAMCUnv
Please see this line. I d
A few things.
If you clarify your question, I'll take my down vote off.
A superficial glance at your code suggests you're trying to write out a variable fileContent
, but at no point do you actually set that variable. Without seeing the error, there;s no way of knowing if that's the problem, or the variable is being created in code that you haven't included.
Another consideration is that you're re-inventing the wheel slightly here. ColdFusion has an inbuilt <cflog> tag or writeLog() statement for writing to log files.
=====
UPDATE (based on updates to the question)
That's a compile error you're getting, and the line that's erroring is not the line you indicated in your code (@ pastebin), which is a bit odd. Can you confirm line 213 is that <cffile>
line? And can you reproduce that line in its entirety (the snippet you quoted was incomplete). But basically the error message is telling you what's wrong: you have a syntax error in your code. It could be in the specific statement the error message says (line and column), although sometimes depending on the code, the CF compiler can get confused and a syntax error in a preceding line might be reported as being further down the file than it actually is. But for starters, post the whole line of code, not just the first bit of it.
comments tl;dr version - This answer worked but asker began asking questions about the new error, he was urged to create a new question.
Answer:
I don't see this line in the link you posted (I searched for api.log
). Invalid CFML construct
typically means you have a syntax error, usually forgetting a closing quote, second pound, or closing your tag (greater than). If the below suggestion doesn't work, look above or below the line containing the cffile for a missing part of a closing pair.
The code you posted:
<cffile action="WRITE" file="#expandpath('API.log')#" output="#filecontent#" addnewline="Yes" fixnewline="No"
...does not have a closing greater than to close your tag. If that is your actual code, I would suspect that is the problem.
<cffile ... >
^^^ this is missing right here
If you're not going to take Adam's suggestion and use cflog (which you should), you also probably want action="append"
or you will keep overwriting the file with the contents of fileContent.
==edit==
On a side note, this will not solve your problem but you should be using cfqueryparam, especially when using user entered data.
For example:
Select *
FROM Purchasers
WHERE PurchaserID = #PurchaserID#
Should be
Select *
FROM Purchasers
WHERE PurchaserID = <cfqueryparam cfsqltype="cf_sql_integer" value="#PurchaserID#">