Autoresponder Plugin throwing Database Errors (Database error 1064 while doing query You have an error in your SQL syntax)

I’m running phpList 3.2.7 and have the Autoresponder plugin version 2.3.2+20160527 installed from github.

During my testing, the autoresonder was working fine but when I uploaded a bunch of emails to various lists yesterday, I got the following errors which I’ve pasted from the command line…

This is the cronjob I use to send emails that generates these errors…

USER=listprocessor; export USER; /usr/bin/php /home/admin/public_html/admin/index.php -pprocessqueue -c /home/admin/public_html/config/config.php

And here are the mysql errrors…

Does anyone know what might solve this?

phpList version 3.2.7 (c) 2000-2017 phpList Ltd, http://www.phplist.com
phpList - Database error 1064 while doing query  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS attributeid, lu.userid AS userid, now() AS value
                    FROM php' at line 1
phpList - Sql error REPLACE INTO phplist_user_user_attribute SELECT  AS attributeid, lu.userid AS userid, now() AS value
                    FROM phplist_autoresponders ar
                    INNER JOIN phplist_message m ON ar.mid = m.id
                    INNER JOIN phplist_listmessage lm ON m.id = lm.messageid
                    INNER JOIN phplist_listuser lu ON lm.listid = lu.listid
                    INNER JOIN phplist_user_user u ON u.id = lu.userid AND u.confirmed = 1 AND u.blacklisted = 0
                    LEFT JOIN phplist_usermessage um ON lu.userid = um.userid AND um.messageid = m.id
                    WHERE ar.id = 10
                    AND (ar.new = 0 || ar.new = 1 && lu.modified > ar.entered)
                    AND (UNIX_TIMESTAMP(lu.modified) + (ar.mins * 60)) < UNIX_TIMESTAMP(now())
                    AND um.userid IS NULL
                    GROUP BY lu.userid
phpList - Database error 1064 while doing query  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS attributeid, lu.userid AS userid, now() AS value
                    FROM php' at line 1
phpList - Sql error REPLACE INTO phplist_user_user_attribute SELECT  AS attributeid, lu.userid AS userid, now() AS value
                    FROM phplist_autoresponders ar
                    INNER JOIN phplist_message m ON ar.mid = m.id
                    INNER JOIN phplist_listmessage lm ON m.id = lm.messageid
                    INNER JOIN phplist_listuser lu ON lm.listid = lu.listid
                    INNER JOIN phplist_user_user u ON u.id = lu.userid AND u.confirmed = 1 AND u.blacklisted = 0
                    LEFT JOIN phplist_usermessage um ON lu.userid = um.userid AND um.messageid = m.id
                    WHERE ar.id = 17
                    AND (ar.new = 0 || ar.new = 1 && lu.modified > ar.entered)
                    AND (UNIX_TIMESTAMP(lu.modified) + (ar.mins * 60)) < UNIX_TIMESTAMP(now())
                    AND um.userid IS NULL
                    GROUP BY lu.userid
phpList - Database error 1064 while doing query  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS attributeid, lu.userid AS userid, now() AS value
                    FROM php' at line 1
phpList - Sql error REPLACE INTO phplist_user_user_attribute SELECT  AS attributeid, lu.userid AS userid, now() AS value
                    FROM phplist_autoresponders ar
                    INNER JOIN phplist_message m ON ar.mid = m.id
                    INNER JOIN phplist_listmessage lm ON m.id = lm.messageid
                    INNER JOIN phplist_listuser lu ON lm.listid = lu.listid
                    INNER JOIN phplist_user_user u ON u.id = lu.userid AND u.confirmed = 1 AND u.blacklisted = 0
                    LEFT JOIN phplist_usermessage um ON lu.userid = um.userid AND um.messageid = m.id
                    WHERE ar.id = 22
                    AND (ar.new = 0 || ar.new = 1 && lu.modified > ar.entered)
                    AND (UNIX_TIMESTAMP(lu.modified) + (ar.mins * 60)) < UNIX_TIMESTAMP(now())
                    AND um.userid IS NULL
                    GROUP BY lu.userid
phpList - Database error 1064 while doing query  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS attributeid, lu.userid AS userid, now() AS value
                    FROM php' at line 1
phpList - Sql error REPLACE INTO phplist_user_user_attribute SELECT  AS attributeid, lu.userid AS userid, now() AS value
                    FROM phplist_autoresponders ar
                    INNER JOIN phplist_message m ON ar.mid = m.id
                    INNER JOIN phplist_listmessage lm ON m.id = lm.messageid
                    INNER JOIN phplist_listuser lu ON lm.listid = lu.listid
                    INNER JOIN phplist_user_user u ON u.id = lu.userid AND u.confirmed = 1 AND u.blacklisted = 0
                    LEFT JOIN phplist_usermessage um ON lu.userid = um.userid AND um.messageid = m.id
                    WHERE ar.id = 26
                    AND (ar.new = 0 || ar.new = 1 && lu.modified > ar.entered)
                    AND (UNIX_TIMESTAMP(lu.modified) + (ar.mins * 60)) < UNIX_TIMESTAMP(now())
                    AND um.userid IS NULL
                    GROUP BY lu.userid
phpList - Database error 1064 while doing query  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS attributeid, lu.userid AS userid, now() AS value
                    FROM php' at line 1
phpList - Sql error REPLACE INTO phplist_user_user_attribute SELECT  AS attributeid, lu.userid AS userid, now() AS value
                    FROM phplist_autoresponders ar
                    INNER JOIN phplist_message m ON ar.mid = m.id
                    INNER JOIN phplist_listmessage lm ON m.id = lm.messageid
                    INNER JOIN phplist_listuser lu ON lm.listid = lu.listid
                    INNER JOIN phplist_user_user u ON u.id = lu.userid AND u.confirmed = 1 AND u.blacklisted = 0
                    LEFT JOIN phplist_usermessage um ON lu.userid = um.userid AND um.messageid = m.id
                    WHERE ar.id = 30
                    AND (ar.new = 0 || ar.new = 1 && lu.modified > ar.entered)
                    AND (UNIX_TIMESTAMP(lu.modified) + (ar.mins * 60)) < UNIX_TIMESTAMP(now())
                    AND um.userid IS NULL
                    GROUP BY lu.userid
phpList - Database error 1064 while doing query  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS attributeid, lu.userid AS userid, now() AS value
                    FROM php' at line 1
phpList - Sql error REPLACE INTO phplist_user_user_attribute SELECT  AS attributeid, lu.userid AS userid, now() AS value
                    FROM phplist_autoresponders ar
                    INNER JOIN phplist_message m ON ar.mid = m.id
                    INNER JOIN phplist_listmessage lm ON m.id = lm.messageid
                    INNER JOIN phplist_listuser lu ON lm.listid = lu.listid
                    INNER JOIN phplist_user_user u ON u.id = lu.userid AND u.confirmed = 1 AND u.blacklisted = 0
                    LEFT JOIN phplist_usermessage um ON lu.userid = um.userid AND um.messageid = m.id
                    WHERE ar.id = 34
                    AND (ar.new = 0 || ar.new = 1 && lu.modified > ar.entered)
                    AND (UNIX_TIMESTAMP(lu.modified) + (ar.mins * 60)) < UNIX_TIMESTAMP(now())
                    AND um.userid IS NULL
                    GROUP BY lu.userid
phpList - Recently sent : 0
phpList - Started [0.0349100000] (179)
phpList - Sending in batches of 500 emails [0.0002070000] (180)
phpList - Processing has started, [0.0007310000] (183)
phpList - 10 campaigns to process. [0.0005080000] (185)
phpList - Processing message 32 [0.0050050000] (202)
phpList - Looking for subscribers [0.0009460000] (207)
phpList - 0 subscribers apply for attributes, now checking lists [0.0009350000] (211)
phpList - No subscribers apply for attributes [0.0001950000] (212)
phpList - Finished this run [0.0008020000] (216)
phpList - Script stage: 6 [0.0004620000] (218)
phpList - Finished, Nothing to do [0.0001710000] (219)
phpList - Finished, All done [0.0009010000] (221)

@bruce7890 It looks like a problem with the user attribute associated with the autoresponder.

There should be a user attribute called “autoresponder_10” (as the sql shows that 10 is the id of the autoresponder), but that attribute doesn’t appear to exist. Possibly deleting the autoresponder and creating a new one will remove the problem.

Thank you Duncan, I’ll give that a go and will let you know how I get on…

Hi Duncan, I just applied the plugin upgrade and the error messages are gone when I manually run the cron command…

However, the emails are still not set… As you said, I’ll delete and then re-create the autoresponders…

I have a hunch that this problem might have arisen because I deleted attributes after creating the autoresponders… I don’t know if that makes any sense but that’s one idea I’ve got right now…

That was what I thought the cause probably was.

The code change is simply to avoid the invalid sql query by validating whether the attribute exists. Now the plugin writes to the event log but otherwise ignores that autoresponder.