Get the results and check whether it has records.
// Check to see if record exists $sql = "SELECT * FROM page_tracking where name ="index.php""; $query = mysqli_query ($conn, $sql); $result=mysqli_fetch_all($query,MYSQLI_ASSOC); if (count($result) > 0) { $sql= "UPDATE page_tracking SET count=count+1 where name="index.php")"; } else { //Insert Query $sql = "INSERT INTO page_tracking (name, count) VALUES ('index.php', '1')"; }