How do you prevent a replica row from being produced inside a table with two posts, neither which are unique? And is this done using MySQL only, or will it require inspections with my PHP script?

This is actually the CREATE query for that table under consideration (two other tables exist, users and roles):

CREATE TABLE users_roles (
user_id INT(100) NOT NULL,
role_id INT(100) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (role_id) REFERENCES roles(role_id)
) ENGINE = INNODB;

I'd like the next query, if performed more often than once, to throw a mistake:

INSERT INTO users_roles (user_id, role_id) VALUES (1, 2);

Please not recommend bitmasks being an answer.

Thanks!

Define both user_id and role_id posts because the primary key for that table.

CREATE TABLE users_roles (
  user_id INT(100) NOT NULL,
  role_id INT(100) NOT NULL,
  PRIMARY KEY(user_id, role_id)
  FOREIGN KEY (user_id) REFERENCES users(user_id),
  FOREIGN KEY (role_id) REFERENCES roles(role_id)
) ENGINE = INNODB;

Secret is known as an amalgamated if this uses several posts, such as this situation.

When the primary secret is already defined, you have to take a look at using unique constraints/indexes.

Without altering what's otherwise understood to be your secrets, you can include a constraint

ALTER TABLE users_roles ADD CONSTRAINT UNIQUE (user_id, role_id);

Once attending college a DB professor explained: "Every single room should have a principal key"

ALTER TABLE users_roles ADD PRIMARY KEY (user_id, role_id);