title: Increment column value if duplicate value found
body: <p>I have a very simple script that imports a CSV of Postcodes and creates a row in a table with it.</p>
  
  <p>I also have a column to store the <code>total</code> number of times that Postcode appears in the CSV file.</p>
  
  <p><strong>Is it possible to increment a column value if a duplicate postcode is found?</strong></p>
  
  <p>So, if there's 2 instances of <strong>w1a 1aa</strong> it would increment the value in the total column. For example:</p>
  
  <pre><code>id | postcode   | total
  0  |  w1a 1aa   | 2
  1  |  g74 1bc   | 1
  2  |  ml10 6qd  | 1
  </code></pre>
  
  <hr>
  
  <p><strong>Table:</strong></p>
  
  <pre><code>id | postcode | total
  </code></pre>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>// connect to db
  $servername = "localhost";
  $username = "";
  $password = "";
  $dbname = "postcodes";
  
  // Create connection
  $conn = mysqli_connect($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  
  foreach($csv as $row) {
  
      $postcode = $row[0];
  
      $sql = 'INSERT INTO postcodes VALUES (NULL, "'.$postcode.'", 1)';
  
      if (mysqli_query($conn, $sql)) {
          echo "New record created successfully";
      } else {
          echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
      }
  
  }
  </code></pre>