Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: aegersz on October 22, 2018, 08:31:12 AM

Title: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: aegersz on October 22, 2018, 08:31:12 AM

https://forum.site-name.org/index.php?action=admin;area=manageboards;sa=board2
Duplicate entry '60-2' for key 'PRIMARY'

Error: Duplicate entry '60-2' for key 'PRIMARY'
Database Error: Duplicate entry '60-2' for key 'PRIMARY'


INSERT INTO smf209_moderators(`id_board`, `id_member`)
VALUES
(60, 2),
(60, 2)
File: /var/www/html/Sources/Subs-Boards.php
Line: 763

call_user_func                    /index.php:176
                                       
AdminMain   

ManageBoards                   Sources/Admin.php:754
 
EditBoard2                   Sources/ManageBoards.php:111

modifyBoard                   Sources/ManageBoards.php:683
   
SMF_DB_MySQLi->insert   Sources/Subs-Boards.php:763

SMF_DB_MySQLi->query   Sources/Subs-Db-mysql.php:1488

SMF_DB_MySQLi->error   Sources/Subs-Db-mysql.php:1171

log_error                            

Sources/Subs-Db-mysql.php:126
Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: aegersz on October 22, 2018, 09:01:31 AM

Ran it manually in phpmyadmin but i wonder why it heppenned ?

INSERT INTO smf209_moderators
(`id_board`, `id_member`)
VALUES
    (60, 2)


SELECT * FROM `smf209_moderators`
Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: Arantor on October 22, 2018, 09:01:59 AM
Did you try to add the same board moderator twice at the same time?
Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: aegersz on October 22, 2018, 09:34:10 AM
yes, i was updating a board and those fields get autofilled.
Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: aegersz on October 22, 2018, 09:37:29 AM
does this code look right to you ?

                        $smcFunc['db_insert']('insert',
                                '{db_prefix}moderators',
                                array('id_board' => 'int', 'id_member' => 'int'),
                                $inserts,
                                array('id_board', 'id_member')
                        );

Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: Arantor on October 22, 2018, 10:04:46 AM
Yes, but if you try to insert two rows the same, it will fail... which is what the original issue was.

Which implies the $inserts got two values, presumably from you trying to add the same person twice unnecessarily.
Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: aegersz on October 23, 2018, 07:45:16 PM
yes BUT i added it successfully as i did not see any duplicate.

it couldn't've been if i added it manually.

maybe a DB anomaly.
Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: Kindred on October 24, 2018, 09:13:34 AM
really....  I know I've told you this before....   you should never, ever, ever, ever edit the database directly
Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: Arantor on October 24, 2018, 09:36:54 AM
Except, as usual we've gone down irrelevant tangents. You adding it manually in the DB is not relevant.

From the UI it appears you tried to add the same user twice as a moderator causing the error originally shown. It is not surprising that if you dint use the UI and don't try to add the same person twice, you don't get an error... what you've basically said is "I have a flat tyre on my car but if I use my bike, it's fine".
Title: Re: Bug ? Error: Duplicate entry '60-2' for key 'PRIMARY'
Post by: aegersz on October 24, 2018, 01:45:32 PM
OK guys, I consider myself told off !

it's only a harmless little DB update, how bad can it be ?

(don't answer that)