EasyCFM.COM ColdFusion Forums / Coding Help! / String index out of range: 0

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: String index out of range: 0

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

ghetto-pixel
02-21-2006 @ 3:51 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 20
Joined: Feb 2006

Hello, good day to everyone Smile ,

I used a tutorial on this site to adapt and code my own "unique hit counter" but I keep getting an error and the cookies wont set, is there a problem with my code?


<CFPARAM NAME="COOKIE.HITS.IP" DEFAULT="">
<CFPARAM NAME="COOKIE.HITS.DATE" DEFAULT="">
<CFQUERY DATASOURCE="#MYSQL.DATABASE#" USERNAME="#MYSQL.USERNAME#" PASSWORD="#MYSQL.PASSWORD#" NAME="GET.HITS">
     SELECT COUNT AS TCOUNT FROM HITS
</CFQUERY>
<CFIF GET.HITS.RECORDCOUNT IS 0>
     <CFQUERY DATASOURCE="#MYSQL.DATABASE#" USERNAME="#MYSQL.USERNAME#" PASSWORD="#MYSQL.PASSWORD#">
          INSERT INTO hits(COUNT) VALUES(1)
     </CFQUERY>
     <CFOUTPUT>
          0
     </CFOUTPUT>
<CFELSE>
     <CFOUTPUT QUERY="GET.HITS">
          #TCOUNT#
     </CFOUTPUT>
</CFIF>
<CFIF (NOT ISDEFINED(COOKIE.HITS.IP) AND NOT ISDEFINED(COOKIE.HITS.DATE)) AND (COOKIE.HITS.IP AND COOKIE.HITS.DATE EQ FALSE OR "")>
     <CFQUERY DATASOURCE="#MYSQL.DATABASE#" USERNAME="#MYSQL.USERNAME#" PASSWORD="#MYSQL.PASSWORD#">
          UPDATE HITS SET COUNT = COUNT + 1
     </CFQUERY>
     <CFCOOKIE DOMAIN=".GHETTOPIXEL.COM" EXPIRES="NOW" NAME="HITS.DATE">
     <CFCOOKIE DOMAIN=".GHETTOPIXEL.COM" EXPIRES="NOW" NAME="HITS.IP">
     <CFSET THIS.DATE=DATEFORMAT(NOW(),"MM/DD/YY")>
     <CFSET THIS.IP=CGI.REMOTE_ADDR>
     <CFCOOKIE DOMAIN=".GHETTOPIXEL.COM" PATH="/" EXPIRES="NEVER" NAME="HITS.DATE" VALUE="#THIS.DATE#">
     <CFCOOKIE DOMAIN=".GHETTOPIXEL.COM" PATH="/" EXPIRES="NEVER" NAME="HITS.IP" VALUE="#THIS.IP#">
     <CFELSEIF (ISDEFINED(COOKIE.HITS.IP) AND ISDEFINED(COOKIE.HITS.DATE)) AND (COOKIE.HITS.IP AND COOKIE.HITS.DATE NEQ FALSE OR "")>
          <CFSET OLDTIME=COOKIE.HITS.DATE>
          <CFSET NEWTIME=DATEFORMAT(NOW(),"MM/DD/YY")>
          <CFIF (DATECOMPARE(OLDDATE,NEWDATE) EQ -1)>
               <CFQUERY DATASOURCE="#MYSQL.DATABASE#" USERNAME="#MYSQL.USERNAME#" PASSWORD="#MYSQL.PASSWORD#">
                    UPDATE HITS SET COUNT = COUNT + 1
               </CFQUERY>
               <CFCOOKIE DOMAIN="ghettopixel.com" EXPIRES="NOW" NAME="HITS.DATE">
               <CFCOOKIE DOMAIN=".GHETTOPIXEL.COM" EXPIRES="NOW" NAME="HITS.IP">
               <CFSET THIS.DATE=DATEFORMAT(NOW(),"MM/DD/YY")>
               <CFSET THIS.IP=CGI.REMOTE_ADDR>
               <CFCOOKIE DOMAIN=".GHETTOPIXEL.COM" PATH="/" EXPIRES="NEVER" NAME="HITS.DATE" VALUE="#THIS.DATE#">
               <CFCOOKIE DOMAIN=".GHETTOPIXEL.COM" PATH="/" EXPIRES="NEVER" NAME="HITS.IP" VALUE="#THIS.IP#">
          </CFIF>
</CFIF>


If somone could tell me what "string index out of range :0" means and why its not setting cookies that would be great, I do have <cfapplication> tag set to allow client cookies and everything in my Application.cfm, and I am on bluedragon till tomorrow when I get my CF7 server up.  Thanks for the help ahead of time Smile

----------
There are Ghetto Pixels everywhere, I just keep mine bundled in one place. [http://www.ghettopixel.com]

This message was edited by ghetto-pixel on 2-21-06 @ 3:53 PM

Webmaster
02-21-2006 @ 3:57 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

DO NOT USE a "." in a varaible or query name.

Remember that thre are scopes in coldfusion (i.e. URL scope, Form Scope, etc).

change this:

<CFQUERY DATASOURCE="#MYSQL.DATABASE#" USERNAME="#MYSQL.USERNAME#" PASSWORD="#MYSQL.PASSWORD#" NAME="GET.HITS">


to this:
<CFQUERY DATASOURCE="#MYSQL.DATABASE#" USERNAME="#MYSQL.USERNAME#" PASSWORD="#MYSQL.PASSWORD#" NAME="GETHITS">


then change accordingly to be the same thing throughout your code.

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email


Website Designed and Developed by Pablo Varando.