Skip to main content
Known Participant
August 3, 2010
Answered

cfpop question

  • August 3, 2010
  • 1 reply
  • 686 views

I'm just getting started with trying to implement an automatic unsubscribe program, and am stymied. So far, I have:

<cfpop action="getHeaderOnly" name="getMessages" server="mail.comcast.net" username="username" password="password">

<cfif #getMessages.recordCount# IS NOT 0>
    <!--- if there are new messages, loop through them --->
    <cfloop query="getMessages">
        <cfif subject IS "Remove">
            <cfquery datasource="cpac">
                DELETE FROM Subscribers
                WHERE Email=#getMessages.from#
            </cfquery>
        </cfif>
    </cfloop>
</cfif>

I've sent an email message from my email account to my email account with "Remove" in the subject line, and get the following error message:

Error executing database inquiry.

Syntax error (missing operator) in query expression 'Email=earachefl@comcast.net"

The error occurred in (template path)

35: <cfquery datasource="cpac">

36: DELETE FROM Subscribers

37: WHERE Email=#getMessages.from#

I can tell by a cfdump that my messages have been retrieved properly, and can tell that the template has found a message with the subject "Remove", and wants to execute the query.

What exactly is the missing operator in my query?

Thanks.

This topic has been closed for replies.
Correct answer ilssac

My first guess would be single quotes around the getMessges.from string variable in the WHERE clause.

An even better version would be to use a <cfqueryparam...> tag around the getmessages.from variable.

1 reply

ilssac
ilssacCorrect answer
Inspiring
August 3, 2010

My first guess would be single quotes around the getMessges.from string variable in the WHERE clause.

An even better version would be to use a <cfqueryparam...> tag around the getmessages.from variable.

earacheflAuthor
Known Participant
August 3, 2010

D'oh!!! You know, I had tried double quotes also "" but forgot that SQL syntax wants single quotes. Arggghhhhh!

Thanks!

Inspiring
August 4, 2010

D'oh!!! You know, I had tried double quotes also "" but forgot that SQL syntax wants single quotes. Arggghhhhh!

Thanks!

Like the previous guy suggested... you should be using <cfqueryparam> for your dynamic values, rather than hardcoding them in your SQL string.

I'd also perhaps try minimising how many hits you're doing to the DB: get a list of the IDs you need to delete, then delete 'em all with the one <cfquery>.

--

Adam