title: How to restrict user from updating same row twice+
body: <p>I'm trying to create a system similar to a Facebook LIKE button. I want to allow a user to like a picture, but only let them like it once. After they have liked it, they should only be able to unlike it.</p>
  
  <p>My current code is:</p>
  
  <pre><code>&lt;?php
  $id = $_GET["picID"];
  
      include 'db.php';
  
      $colID  = str_replace('_', ' ', $_GET['picID']);
      $colID  = mysql_escape_string($picID);
  
      $sql = "SELECT * FROM picture WHERE id = $id";
      $result = mysql_query($sql) or die (mysql_error()."&lt;br/&gt;".sql); 
      $row = mysql_fetch_array($result);
  
  
      $update = "UPDATE picture SET likes=likes+1 WHERE id='$id'";
      mysql_query($update) or die (mysql_error()."&lt;br/&gt;".update);     
      echo "Thank you";
  
  ?&gt;
  </code></pre>
  
  <p>Currently I use a hyperlink to trigger the 'Like' action:</p>
  
  <pre><code>&lt;a href='like.php?colID=$row[id]'&gt;Like&lt;/a&gt;
  </code></pre>
  
  <p>At the end I'd like to change this to AJAX so the user can simply click Like (as on Facebook) without any page change. I'm still reading up on how to do this. Is there a particular name for this task? Or can someone show me show I could do this?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The user needs to be logged in to be able to like a picture. I have two unlinked tables, <code>User</code> and <code>Pictures</code>. Currently a user can just keep clicking 'Like' and it adds 1 to the like column.</p>