So, I am writing an SQL Query, as you do, and I have stumbled across an issue. What I am wanting to do is fire a query at the database every time a unique user visits a certain page. The unique-ness is done through session_id(), as that is generally quite reliable.
What I want is an SQL query which inserts a row of data into two columns, but ONLY if those two columns don't already have the same value.
if user x visits the page named page1, then in the database, it will log as shown below:
+------------+---------+
| page_name  | user_id |
+------------+---------+
|    page1   |    x    |
+------------+---------+
How would I go about writing a query which checks the table to see if the data being inserted will be a duplicate?
My current query is as follows (it's just a standard insert query):
INSERT INTO `page_views` (`page_name`, `user_id`) VALUES ('.$pageName.', \''.session_id().'\')
 
     
     
    