Skip to main content
June 8, 2008
Question

Query problem again

  • June 8, 2008
  • 8 replies
  • 824 views
Will I ever get this!

I have a form template which runs fine (it registers a user of my discussino board):

<h2>Register here to post comments to any forum on this site </h2>

<form action="Education - Bulletin Board - Register - code.cfm" method="post">

<p>
<strong>Username: </strong>
<input type="text" name="user" />
</p>
<p><br />
<strong>Password: </strong>
<input type="password" name="pass" />
</p>
<p><br />
<strong>Your mother's maiden name (a security precaution if you forget your username/password and need to retrieve them): </strong>
<input type="text" name="MaidenName" />
</p>
<p><br />
<strong>Email address (optional - in case I need to contact you about your posts): </strong>
<input type="text" name="email" />
</p>

<p><br />
<p>
<input type="submit" value="Register!" />
<input type="button" value="Back" onClick="self.location='index.cfm';" />
</p>
</form>

</body>

Now I want to check if the username and password have been taken by a previous user so I use this code:

<cfif NOT structIsEmpty(form)>
<cfquery name="CheckUserName" datasource= "Education Forum">
SELECT UserName, Count(UserName) as Duplicates
FROM ForumUsers
WHERE ForumUsers.UserName=#form.user#
GROUPBY ForumUsers.UserName
</cfquery>
<cfquery name="CheckPassword" datasource= "Education Forum">
SELECT PassWord, Count(PassWord) as Duplicates
FROM ForumUsers
WHERE ForumUsers.Password=#form.PassWord#
GROUPBY Password
</cfquery>

I just count how many times the password has been used. If it has been used more than once I'll later ask the new user to enter a different password. Unfortunately, Coldfusion has a problem with this query. Specifically, it gives me the error:

Access Driver] Syntax error (missing operator) in query expression 'ForumUsers.UserName=jimmy GROUPBY ForumUsers.UserName'.

The Error Occurred in C:\CFusionMX\wwwroot\Education\Bulletin Board\Education - Bulletin Board - Register - code.cfm: line 7

5 : WHERE ForumUsers.UserName=#form.user#
6 : GROUPBY ForumUsers.UserName
7 : </cfquery>
8 : <cfquery name="CheckPassword" datasource= "Education Forum">
9 : SELECT PassWord, Count(PassWord) as Duplicates

SQL SELECT UserName, Count(UserName) as Duplicates FROM ForumUsers WHERE ForumUsers.UserName=jimmy GROUPBY ForumUsers.UserName
DATASOURCE Education Forum
VENDORERRORCODE -3100
SQLSTATE 42000

I've run into this before, but I don't seem to be able to grasp the general principle involved.

I'd be very grateful if someone could explain the error in this particular case and how I can avoid the problem in the futre.

Thanks, once again, very much in advance.
    This topic has been closed for replies.

    8 replies

    Inspiring
    June 9, 2008
    doh! good eyes! i should probably go have mine checked... :)

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    June 9, 2008
    Yes, that was it! Thanks everybody. Much apprecite your help.
    June 8, 2008
    Isnt GROUP BY supposed to be two words?
    June 8, 2008
    Thanks for the suggestions. I've changed the code to incorporate the advice as far as I can. It now reads:

    <cfif NOT structIsEmpty(form)>
    <cfparam name = "form.user" default = 0>
    <cfparam name = "form.password" default = 0>
    <cfparam name = "form.Email" default = 0>
    <cfparam name = "form.MaidenName" default = 0>
    <cfquery name="CheckUserName" datasource= "Education Forum">
    SELECT Uname, Count(Uname) as Duplicates
    FROM ForumUsers
    WHERE ForumUsers.Uname='#form.user#'
    GROUPBY ForumUsers.Uname
    </cfquery>
    <cfquery name="CheckPassword" datasource= "Education Forum">
    SELECT Pword, Count(Pword) as Duplicates
    FROM ForumUsers
    WHERE ForumUsers.Pword="AK"
    GROUPBY Pword
    </cfquery>

    Unfortunately, it still fails giving me the same error:

    Access Driver] Syntax error (missing operator) in query expression 'ForumUsers.Uname='adk' GROUPBY ForumUsers.Uname'.

    The Error Occurred in C:\CFusionMX\wwwroot\Education\Bulletin Board\Education - Bulletin Board - Register - code.cfm: line 11

    9 : WHERE ForumUsers.Uname='#form.user#'
    10 : GROUPBY ForumUsers.Uname
    11 : </cfquery>
    12 : <cfquery name="CheckPassword" datasource= "Education Forum">
    13 : SELECT Pword, Count(Pword) as Duplicates

    SQL SELECT Uname, Count(Uname) as Duplicates FROM ForumUsers WHERE ForumUsers.Uname='adk' GROUPBY ForumUsers.Uname
    DATASOURCE Education Forum
    VENDORERRORCODE -3100
    SQLSTATE 42000

    I think its just a SQL error as I get the same failure message if I replace '#form.user#' with say 'GAK'.

    Any further suggestions would be greatly appreciated.

    P.S. I'm still a novice, so how would I use <cfqueryparam> tags here?
    Inspiring
    June 8, 2008
    and, as jdeline suggested, #form.user# and #form.PassWord# should be
    '#form.user#' and '#form.PassWord#'.

    but better yet start using <cfqueryparam> tags before it is too late...

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    June 8, 2008
    iirc, USERNAME and PASSWORD are reserved words in Access and you should
    avoid using them for your table/field names....

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    June 8, 2008
    Thanks for the suggestion, but it didn't work. I'd previously tried double quotes and that didn't work either.

    It also fails if I replace #form.PassWord# with a string like:
    ='GK' or ="GK"

    I'm sure it's very simple, but I just can't figure what it is.

    Thanks again for the help
    June 8, 2008
    Try single quotes: 5 : WHERE ForumUsers.UserName='#form.user#'