I have a MySQL table with 2 columns, in the first one is an IP adress and in the second one is a integer which should be incremented.
When a new IP visits the website, integer corresponding to that IP should be incremented by 1.
The PHP scrip should also handle the case when IP address is already present in database.
This is for updating the integer:
UPDATE user SET points = points + 1 WHERE code = '$u'
And this is for adding a new ip to the database (I use the attribute “unique” that no double values could be saved):
INSERT IGNORE INTO $DB_Table (ip,code) values(INET_ATON('$ip'),'$code')
Now I want that the integer is incremented by 1 only when a new IP visits the website. It would be great if the I can reduce the two queries and get the job done in 1 query. Thank you for any help.
INSERT INTO $DB_Table (ip,code) values(INET_ATON('$ip'),'$code') ON DUPLICATE KEY UPDATE user SET points = points + 1 WHERE code = '$u'In the MYSQL table have the
pointsDEFAULT = 1