mrprozac Posted December 25, 2008 Share Posted December 25, 2008 Hi, I'm writing a search script for my website and want to count the searches, i want to use MySQL for that. I want to insert the search query to MySQL and update the count value. Example. If 'query1' is not found in the database insert 'query1' in the database, if 'query1' is already present in the database, update the count value with +1 (value + 1) Could someone help me with a script to perform this? Link to comment https://forums.phpfreaks.com/topic/138389-solved-insert-record-to-mysql-if-the-record-is-not-in-the-database-else-update/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 25, 2008 Share Posted December 25, 2008 Look at using an INSERT with the ON DUPLICATE KEY UPDATE clause - http://dev.mysql.com/doc/refman/5.0/en/insert.html Link to comment https://forums.phpfreaks.com/topic/138389-solved-insert-record-to-mysql-if-the-record-is-not-in-the-database-else-update/#findComment-723584 Share on other sites More sharing options...
mrprozac Posted December 25, 2008 Author Share Posted December 25, 2008 Look at using an INSERT with the ON DUPLICATE KEY UPDATE clause - http://dev.mysql.com/doc/refman/5.0/en/insert.html thank you for the quick reply. I'm going to try it out right away. Link to comment https://forums.phpfreaks.com/topic/138389-solved-insert-record-to-mysql-if-the-record-is-not-in-the-database-else-update/#findComment-723585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.