"INSERT INTO clients (id, username, passwd, groups, status_all, status_1, status_2, status_3)
VALUES ('id','username" . $txn_id . $i . "','" . $passwd . "','paypal','0','0','1','1');";
Well, look at the value you're trying to insert as clients.id, the string literal 'id'. Then look at the table definitiion, e.g. with
SHOW CREATE TABLE clients
and you are likely to find that id is an unsigned integer, which means that 'id' has to be converted from string to integer, and since the string doesn't contain leading numerals, it will be converted to 0.
A primary key must always be unique within its table, and the first time you insert 0 into clients.id, it is. The second time you insert 0, it's not, thus
duplicate entry '0'