Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
1.3k views
in Q2A Core by
edited
When I click "vote" button, it displays "A database error occurred." Why?

My Q2A is 1.4 beta 2

MySQL version: 5.0
by
Please check your web server's error_log file to see what is logged for this error, and post it here. You can also switch off Javascript and click the vote buttons, to have the error displayed on the web page.
by
edited by
I'm currently evaluating q2a and have come across this too.

Apache error log: [error] [client 127.0.0.1] Question2Answer MySQL query error 1364: Field 'flag' doesn't have a default value, referer: http://localhost:8080/q2a/index.php

I'm running Apache/2.0.64 (Win32) PHP/5.2.17 and MySQL 5.5.13.

Any ideas?
by
edited by
I am getting the same error in the current version of Q2A.  is it a stupid user problem at my end? Or have I luckily found another case... 8^(

I did look at the code... tried to reapply Gid's fixes, still the error appears.

1 Answer

+2 votes
by

Thanks for this - it's a bug in Q2A which shows up under certain versions/configurations of MySQL which don't use an implicit default value for a column. You can fix it by making the following changes in qa-db-votes.php:

In function qa_db_uservote_set(...), change:

'INSERT INTO ^uservotes (postid, userid, vote) VALUES (#, #, #) ON DUPLICATE KEY UPDATE vote=#',

... to ...

'INSERT INTO ^uservotes (postid, userid, vote, flag) VALUES (#, #, #, 0) ON DUPLICATE KEY UPDATE vote=#',

Then in function qa_db_userflag_set(...) change:

'INSERT INTO ^uservotes (postid, userid, flag) VALUES (#, #, #) ON DUPLICATE KEY UPDATE flag=#',

... to ...

'INSERT INTO ^uservotes (postid, userid, vote, flag) VALUES (#, #, 0, #) ON DUPLICATE KEY UPDATE flag=#',

These fixes will be rolled into the 1.4.1 release.

asked Sep 6, 2013 in Q2A Core by anonymous A database error occurred
...