Copy link to clipboard
Copied
I am maintaining an very old website built with ColdFusion 7 in my org, but I am very new to ColdFusion. We have a newsbriefs module which worked very well before last week. However, from last week, it started throwing me an error when I try to search the articles (Please see below for the error messages). Can anybody tell me what's wrong? Is it something wrong with the java environment on the server or something wrong with the code? How should I fix this problem? Everything else works fine on this site except for the searching articles by date or keywords. Any advices or suggestions would be greatly appreciated!!!
Resources:
| |||||||||
| |||||||||
| Stack Trace (click to expand) |
at cfviewbydate_action2ecfm1313219662.runPage(E:\InetPub\wwwroot\sitename\newsbriefs\CF\viewbydate_action.cfm:49)java.lang.IllegalArgumentException: MONTH |
createdate(x.news_year,x.news_month,x.news_day)
Like I mentioned, it sounds like your input contains an invalid month (ie outside the valid range of 1-12). Dump your query and check the news_month values. It sounds like one of them is invalid. and that is why you are getting the error.
<cfdump var="#x#">
Would you please advise me where to fix the problem? Thank you!
If that is the problem, you need to fix the invalid data in your database table first. Then add some form validation to prevent those
...Copy link to clipboard
Copied
It's pretty much impossible to say much that's sensible about this without you posting the code that the error msg is identifying as being a problem.
--
Adam
Copy link to clipboard
Copied
Thanks very much for you quick response! Here are some codes related to this action:
Page viewbydate.cfm (no problem on this page, but on the following page):
<cfoutput>
<cfinclude template="menu.cfm">
<cfif isdefined('news_title')>
<cfupdate datasource="newsbriefs" tablename="news">
The article titled #news_title# has been updated in the database.<br />
</cfif><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>View By Date</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body>
<form name="form" method="post" action="viewbydate_action.cfm">
<cfif isdefined('makeissue') and #makeissue# eq true>
<cfquery datasource="newsbriefs" name="ii">
SELECT TOP 1 ISSUE.ISSUE_ID, finalize
FROM ISSUE
ORDER BY ISSUE.ISSUE_ID DESC;
</cfquery>
<cfif #ii.finalize# eq false>
<cfset form.issue_id = #ii.issue_id#>
<cfelse>
<cfset form.issue_id = #ii.issue_id#+1>
</cfif>
Create Issue: Step 1<input type="hidden" name="issue_id" value="#form.issue_id#"></cfif>
<table border="0">
<tr>
<td colspan="3"><div align="right">Select stories by </div></td>
<td colspan="3"><select name="criteria">
<option value="added">date added</option>
<option value="story">story date</option>
</select></td>
</tr>
<cfset current = now()>
<cfset twoweeks = current-14>
<tr>
<td colspan="6"> </td>
</tr>
<tr>
<td>Month</td>
<td>
<select name="frommonth">
<cfloop from="0" to="11" step="1" index="add">
<option value="#dateformat(dateadd('m', add, twoweeks), 'm')#">
#dateformat(dateadd('m', add, twoweeks), 'mmmm')#</option>
</cfloop>
</select>
</td>
<td>Day</td>
<td>
<select name="fromday">
<cfloop from="1" to="31" step="1" index="add">
<option value="#add#" <cfif #dateformat(twoweeks, 'd')# eq #add#>selected</cfif>>#add#</option>
</cfloop>
</select>
</td>
<td>Year</td>
<td>
<select name="fromyear">
<cfloop from="-1" to="1" step="1" index="add">
<option value="#dateformat(dateadd('yyyy', add, twoweeks), 'yyyy')#"
<cfif #dateformat(dateadd('yyyy', add, twoweeks), 'yyyy')# eq #dateformat(twoweeks, 'yyyy')#>selected</cfif>>
#dateformat(dateadd('yyyy', add, twoweeks), 'yyyy')#</option>
</cfloop>
</select>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Month</td>
<td><select name="tomonth">
<cfloop from="0" to="11" step="1" index="add">
<option value="#dateformat(dateadd('m', add, current), 'm')#">
#dateformat(dateadd('m', add, current), 'mmmm')#</option>
</cfloop>
</select>
</td>
<td>Day</td>
<td> <select name="today">
<cfloop from="1" to="31" step="1" index="add">
<option value="#add#" <cfif #dateformat(current, 'd')# eq #add#>selected</cfif>>#add#</option>
</cfloop>
</select>
</td>
<td>Year</td>
<td> <select name="toyear">
<cfloop from="-1" to="1" step="1" index="add">
<option value="#dateformat(dateadd('yyyy', add, current), 'yyyy')#"
<cfif #dateformat(dateadd('yyyy', add, current), 'yyyy')# eq #dateformat(current, 'yyyy')#>selected</cfif>>
#dateformat(dateadd('yyyy', add, current), 'yyyy')#</option>
</cfloop>
</select>
</td>
</tr>
<tr>
<td colspan="6"><input type="submit" value="Get Articles"></td>
</tr>
</table>
</form>
</body>
</html>
</cfoutput>
Here is the viewbydateaction.cfm (error message returned on this page😞
<cfoutput>
<!--- CREATE DATES FOR THE FROM AND TO DATES ON SUBMIT PAGE --->
<cfif isdefined('form.fromyear')>
<cfset fromdate = #createdatetime(form.fromyear,form.frommonth,form.fromday,0,0,0)#>
<cfset todate = #createdatetime(form.toyear,form.tomonth,form.today,23,59,59)#>
</cfif>
<!--- GET ALL STORIES --->
<cfquery name="z" datasource="newsbriefs" cachedwithin="#createtimespan(0,0,15,0)#">
select *
from news
</cfquery>
<cfquery datasource="newsbriefs" name="y">
select distinct news_category
from news
order by news_category
</cfquery>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>View Articles</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body>
<cfinclude template="menu.cfm">
<form name="form" method="post" action="preview.cfm">
<cfif isdefined('form.issue_id') and #form.issue_id# neq "">Create Issue: Step 2<input type="hidden" name="issue_id" value="#form.issue_id#"><cfset makeissue = true></cfif><table border="1">
<cfloop query="y">
<cfquery datasource="newsbriefs" name="a">
select *
from category
where category_id = #y.news_category#
</cfquery>
<tr><td colspan="2"><h1>#a.category_name#</h1></td></tr>
<cfquery datasource="newsbriefs" name="x">
select *
from news
where news_category = #y.news_category#
order by news_category,news_year desc,news_month desc,news_day desc
</cfquery>
<cfquery datasource="newsbriefs" name="ii">
SELECT TOP 1 ISSUE.ISSUE_ID, finalize
FROM ISSUE
ORDER BY ISSUE.ISSUE_ID DESC;
</cfquery>
<cfloop query="x">
<cfset storydate = '#dateformat(createdate(x.news_year,x.news_month,x.news_day), 'd mmmm yyyy')#'>
<cfif #form.criteria# eq 'story'>
<cfif #storydate# gte #fromdate# and #storydate# lte #todate#>
#x.news_title#<br>
#storydate#
<br>
<br></cfif>
<cfelse>
<cfif #x.added# gte #fromdate# and #x.added# lte #todate#>
<tr><td rowspan="4" width="20">
<cfif isdefined('makeissue') and #makeissue# eq true><input type="checkbox" name="storyid" value="#x.news_id#">Add
<cfif #ii.finalize# eq false>to temp issue</cfif></cfif><br>
<br><cfquery datasource="newsbriefs" name="b">
select *
from news_issue
where news_id = #x.news_id#
</cfquery>
<cfif isdefined('b.issue_id') and #b.issue_id# neq "">
<cfloop query="b">
issue #b.issue_id#<Br>
</cfloop><cfelse> </cfif>
</td><td><a href="editarticle.cfm?news_id=#x.news_id#">#x.news_title#</a></td></tr>
<tr><td>#storydate#</td></tr>
<tr><td>#news_text#</td></tr>
<tr><td>#news_source#</td></tr></cfif>
</cfif>
</cfloop>
<tr><td colspan="2"> </td></tr>
</cfloop>
</table>
<input type="submit" value="NEXT >>">
</form>
</body>
</html>
</cfoutput>
Copy link to clipboard
Copied
That is a little too much code to wade through ;-). Can you narrow it down to code within the vicinity of the error? The error message reports the problem is near line 49.
I have only skimmed, but based on the error my guess is you are trying to create a date with an invalid month number. For example, using createDate(2011, 0, 14) would cause that error because "0" is not a valid month number ie (January=1 to December=12)
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f80.html
Copy link to clipboard
Copied
Sorry for the long post and reposting ( did not figure out how to edit the previous post).
Here is the code having the issue:
47 : </cfquery>
48 : <cfloop query="x">
49 : <cfset storydate = '#dateformat(createdate(x.news_year,x.news_month,x.news_day), 'd mmmm yyyy')#'>
50 : <cfif #form.criteria# eq 'story'>
51 : <cfif #storydate# gte #fromdate# and #storydate# lte #todate#>
And here is the code at the beginning of this page:
<!--- CREATE DATES FOR THE FROM AND TO DATES ON SUBMIT PAGE --->
<cfif isdefined('form.fromyear')>
<cfset fromdate = #createdatetime(form.fromyear,form.frommonth,form.fromday,0,0,0)#>
<cfset todate = #createdatetime(form.toyear,form.tomonth,form.today,23,59,59)#>
</cfif>
Would you please advise me where to fix the problem? Thank you!
Copy link to clipboard
Copied
createdate(x.news_year,x.news_month,x.news_day)
Like I mentioned, it sounds like your input contains an invalid month (ie outside the valid range of 1-12). Dump your query and check the news_month values. It sounds like one of them is invalid. and that is why you are getting the error.
<cfdump var="#x#">
Would you please advise me where to fix the problem? Thank you!
If that is the problem, you need to fix the invalid data in your database table first. Then add some form validation to prevent those invalid values from occurring again.
Message was edited by: -==cfSearching==-
Copy link to clipboard
Copied
Thanks for your responses and advices. While I am still searching for a solution, if you do not mind, I'd like to ask why this stopped working suddenly (no any changes made in at least 2 years)? We are using MS Access 2000 as the DB, and this module had been working correctly many years. I checked with the server admin, he told me that there were just some regular daily updates on the server before the errors appeared. The news_year, news_month, and news_day are "number" type in DB. Since other pages involving the search by date actions are also having this problem, I do not know if it is a good idea to make some changes to the code one by one. Scratching my head now...
As advised, I used <cfdump var=#z.news_month#> after query:
<cfquery datasource="newsbriefs" name="x">
select *
from news
where news_category = #y.news_category#
order by news_category,news_year desc,news_month desc,news_day desc
</cfquery>
And the returned value is 11, but in the database, the news_month value of the very first record is 12, and the last record is 1.
Then I tried the dump on another page which having the same error (see below) and the returned value is correct: 12 (the newest record's month in DB).
294 : <cfset date="#CreateDate(news_year,news_month,1)#">
295 : <cfelse>
296 : <cfset datef="#DateFormat(CreateDate(news_year,news_month,news_day),'d mmmm yyyy')#">
297 : <cfset date="#CreateDate(news_year,news_month,news_day)#">
298 : </cfif>
What should I do to fix? I know I am asking a very dumb question, please forgive my ignorance.
Thank you!
Copy link to clipboard
Copied
Ha, I figured out where the problem is: there was a date in the database which is wrong: Nov 31, 2011. Obviously there is no 31 in November, so I changed the date in the database and it worked! Horary!!!
Many thanks to cfsearching and Adam for your responses and ideas!
Copy link to clipboard
Copied
Pre-database validation for the win. Guess you're storing them as some kind of number of varchar then? If only there was a data type for dates... ![]()
Copy link to clipboard
Copied
Pre-database validation for the win. Guess you're storing them as some kind of number of varchar then? If only there was a data type for dates...
I think he is storing the month, day and year separately. But agreed they need to add validation or this could easily happen again.
Copy link to clipboard
Copied
You are right, the date, month, and year are stored separatly. I am learning things from you responses
. I probably will not have extra time to update this module or something as long as it works for now because I am developing a new system. Very much appreciate your help and appologize for the wrong marking actions (new user and do not know the rules).
Copy link to clipboard
Copied
wangchoyqz wrote:
Ha, I figured out where the problem is: there was a date in the database which is wrong: Nov 31, 2011. Obviously there is no 31 in November, so I changed the date in the database and it worked! Horary!!!
Many thanks to cfsearching and Adam for your responses and ideas!
Wangchoyqz,
You shouldn't have offered the points to yourself. You contributed nothing to the solution. I would have done the decent thing, and offered the points as follows:
5 points to Adam for:
It's pretty much impossible to say much that's sensible about this without you posting the code that the error msg is identifying as being a problem
5 points to -==cfSearching==- for:
That is a little too much code to wade through ;-). Can you narrow it down to code within the vicinity of the error? The error message reports the problem is near line 49.
I have only skimmed, but based on the error my guess is you are trying to create a date with an invalid month number. For example, using createDate(2011, 0, 14) would cause that error because "0" is not a valid month number ie (January=1 to December=12)
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f80.html
10 points to -==cfSearching==- for:
If that is the problem, you need to fix the invalid data in your database table first. Then add some form validation to prevent those invalid values from occurring again.
Copy link to clipboard
Copied
Sorry, I did not know the rules here. I just wanted to mark the problem was solved and did not aware there was an earning points thing. I do not care the points at all, was just seeking for solution. I really appreciate CFsearching and Owain's advices. Can anybody direct me how to change the marks? Thank you!
Copy link to clipboard
Copied
I do not care the points at all,
I doubt many people do... I mean... what purpose do they serve?
I think marking the actual answer as "the answer" (irrespective of who posts it, and how many other people helped on the journey) is more useful than doling out points to people. So I think you have done exactly the right thing, marking your own follow-up as the answer.
--
Adam
Copy link to clipboard
Copied
Thanks Adam! That's all right. The only thing I care is the ways to the solution ![]()
I figured out how to change the marks and made the changes ![]()
Let's close the discussion on this thread. The problem is solved, thank you all!!!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more