Add unique constraint on combination of 2 columns
A constraint like:

UNIQUE(cartID, productID)


means that the combination of cartID and productID is unique, not the individual columns. It is however possible that something in your syntax makes MySQL ignore the constraint. Can you try the following:

CREATE TABLE Orders
( cartID int not null
, productID int not null
, unique (cartID, productID) );

insert into Orders (cartID, productID) values (10, 7), (10,8), (11,7),(11,7);
ERROR 1062 (23000): Duplicate entry '11-7' for key 'cartID'

insert into Orders (cartID, productID) values (10, 7), (10,8), (11,7);
Query OK, 3 rows affected (0.05 sec)
Records: 3  Duplicates: 0  Warnings: 0