Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
  • Register
Welcome to the Q&A for Question2Answer.

If you have questions about the platform, click here to ask and please use English.

If you just want to try Q2A, please use the demo, which also grants admin access.

Apr 29: Q2A 1.5.2

When I click "vote" button, it displays "A database error occurred." Why?

+3 votes
When I click "vote" button, it displays "A database error occurred." Why?

My Q2A is 1.4 beta 2

MySQL version: 5.0
asked Jun 11, 2011 in Q2A Core by anonymous
edited Jun 11, 2011
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.
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?

1 Answer

+2 votes

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.

answered Jun 28, 2011 by gidgreen