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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visit counter and evaluate problem 1

Status
Not open for further replies.

PTmon

IS-IT--Management
Mar 8, 2001
284
US
Hi,
I'm trying to make a very simple counter for when visitors sign in to my site. I can't figure out why this is not working. The database field is a number field.
---
<cfoutput>
<cfquery name=&quot;getuser&quot; datasource=&quot;#application.dsn#&quot;>
SELECT visits
FROM users
WHERE username = '#session.username#'
</cfquery>
<cfquery name=&quot;counter&quot; datasource=&quot;#application.dsn#&quot;>
UPDATE users
SET visits = #Evaluate(&quot;getuser.visits + 1&quot;)#
WHERE username = '#session.username#'
</cfquery></cfoutput>
---

An error occurred while evaluating the expression:
#Evaluate(&quot;getuser.visits + 1&quot;)#
Cannot convert to number.

Please, check the ColdFusion manual for the allowed conversions between data types


The error occurred while processing an element with a general identifier of (#Evaluate(&quot;getuser.visits + 1&quot;)#)

Any help is appreciated!
Thanks,
pt

 
Have you tried it without Evaluate()?
Code:
<cfquery name=&quot;getuser&quot; datasource=&quot;#application.dsn#&quot;>
SELECT visits
FROM users
WHERE username = '#session.username#'
</cfquery>

<cfquery name=&quot;counter&quot; datasource=&quot;#application.dsn#&quot;>
UPDATE users
SET visits = (#getuser.visits# + 1)
WHERE username = '#session.username#'
</cfquery>

BTW, you don't need the cfoutput tags around queries.

What type of database are you using? You might could combine this whole thing into one query:
Code:
<cfquery name=&quot;counter&quot; datasource=&quot;#application.dsn#&quot;>
UPDATE users
SET visits = (visits + 1)
WHERE username = '#session.username#'
</cfquery>

Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Thanks Ecobb, this is an access database. I found part of my problem was up a little further in the code, I was setting the session.username variable incorrectly, which caused my query to find nothing. Ugh. Your way is much simpler thanks! I am using it and it works perfectly now. I didn't think I needed the cfoutputs, but was gettign frustrated and trying everything.<sigh>
Thanks again!
pt

 
No problem, glad I could help!



Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top