Insert counter if doesn't exist otherwise update it.
I want to limit the uploads on a site to 3 uploads per user.
I have therefore created a separate table to store a count of the uploads per email address as follows
Before inserting a record in the uploads table I want to check the count and insert or increment depending on which is necessary.
CREATE TABLE IF NOT EXISTS `uploadsperuser` (
`strEmail` varchar(255) NOT NULL,
`intCount` int(3) NOT NULL,
PRIMARY KEY (`strEmail`,`intCount`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Is the following close to what I need?
$biEmail = "firstname.lastname@example.org";
$sql = "INSERT INTO uploadsperuser (strEmail, intCount) VALUES ($biEmail, 1) ON DUPLICATE KEY UPDATE intCount = intCount + 1";