Hi am trying to run a rating system. This works cool but when it inserts the very first time. I try to add again. I have applied the check that only one vote will be processed from a ipaddress but somehow it is not working: ihave the following component which process but some how it is not working. can anyone guide me what i am doing wrong.
<cffunction name="addItemRating" returntype="string" access="remote" hint="I add an item rating">
<cfargument name="itemID" required="true" type="string">
<cfargument name="rating" required="true" type="numeric">
<cftry>
<cfset ipaddr = #cgi.REMOTE_ADDR#>
<cfquery name="checkrating" datasource="#request.dsn#">
SELECT itemID, rating, ipaddr FROM
faqmanager_ratings
WHERE
ipaddr = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.ipaddr#">
</cfquery>
<cfif checkrating.recordcount>
<cfset newrate = arraysum(checkrating['rating']) / checkrating.recordcount>
<cfquery name="updaterating" datasource="#request.dsn#">
UPDATE
faqmanager_ratings
SET
Rating = <cfqueryparam cfsqltype="cf_sql_bigint" value="#newrate#">
WHERE
itemID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.itemID#">
</cfquery>
<cfelse>
<cfquery name="insertRating" datasource="#request.dsn#">
insert into faqmanager_ratings(itemID, Rating, ipaddr) values
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.itemID#">,
<cfqueryparam cfsqltype="cf_sql_bigint" value="#arguments.rating#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#ipaddr#">)
</cfquery>
</cfif>
<cfset result = "OK">
<cfcatch type="ANY">
<cfset result = "#cfcatch.type# - #cfcatch.message#">
</cfcatch>
</cftry>
<cfreturn result>
</cffunction>
also i want if ipaddress is different, it should update the rating with new rating figure as described above in
<cfset newrate>