I have the following table structure:
CREATE TABLE IF NOT EXISTS `reports` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`day` int(11) NOT NULL,
`uid` int(1
just use INSERT...ON DUPLICATE KEY UPDATE
INSERT INTO reports_adv (day, uid, siteid, cid, visits)
VALUES ('$day', '$uid', '$sid', '$cid', 1)
ON DUPLICATE KEY UPDATE visits=visits+1;
but before anything else, you should define a UNIQUE
constraint on the columns.
ALTER TABLE reports_adv ADD CONSTRAINT tb_uq UNIQUE (day, uid, siteid, cid)