title: How to properly add rate if client IP does not exist from 'votes' table
body: <p>Hello Stack Overflow Community.</p>
  
  <p>I've made two topics so far about rating system and happily with your help I've managed to achieve it. It works properly, just everyone can vote so I made it to add client's IP in database table 'votes' after each voting. I'd like to help me to make a check like: 1) If client has already voted to does not store its rating in database.</p>
  
  <p>Also how can I avoid inserting postid and ip is they already exist in 'votes'?
  For example, I vote once for post with id 2 and it creates:
   - id: 1
   - postid: 2
   - ip: client's IP</p>
  
  <p>When vote once again for the same post it creates same info so this is useless and should be blocked..</p>
  
  <p>Votes table structure:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `votes` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `postid` int(11) NOT NULL,
    `ip` varchar(15) DEFAULT NULL,
    `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p><strong><em>Updated: /Full Rate.php/</em></strong></p>
  
  <pre><code>    &lt;?php 
  
  $servername = "localhost";
  $username = "root";
  $password = "oregon";
  $dbname = "project";
  
      try {   
          $connection = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
          $connection-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  
  
          $postid = $_POST['post_id'];
          $ip = $_SERVER['REMOTE_ADDR'];
          $sql = $connection-&gt;prepare("SELECT postid, ip FROM votes WHERE ip = :ip");
          $sql-&gt;bindParam(':ip', $ip, PDO::PARAM_STR); 
          $sql-&gt;execute();
          if($sql-&gt;rowCount() &gt; 0){
          die("You already voted");
          }   
  
          $postid = $_POST['post_id'];
          $ip = $_SERVER['REMOTE_ADDR'];
          $sql = $connection-&gt;prepare("INSERT INTO votes (postid, ip) VALUES (:postid, :ip)");
          $sql-&gt;bindParam(':postid', $postid);
          $sql-&gt;bindParam(':ip', $ip);    
          $sql-&gt;execute();    
  
          if (isset( $_POST['slct']) &amp;&amp; $_POST['slct'] === "1") {
              $rate = "1";
          } else if (isset( $_POST['slct']) &amp;&amp; $_POST['slct'] === "2") {
              $rate = "2";
          } else if (isset( $_POST['slct']) &amp;&amp; $_POST['slct'] === "3") {
              $rate = "3";
          } else if(isset( $_POST['slct']) &amp;&amp; $_POST['slct'] === "4") {
              $rate = "4";
          } else if(isset( $_POST['slct']) &amp;&amp; $_POST['slct'] === "5") {
              $rate = "5";
          } else {
              $rate = "0";
          }
          $id = $_POST['post_id'];
          $rating = $_POST['rate'];
          $clicks = $_POST['clicks'];
          $total_clicks = $clicks + '1';
          $max_rate = $rating + $rate;
          if($_POST['slct'] == "0") {
              $clicks = $_POST['clicks'];
              $total_clicks = $clicks + '0';
          }   
  
          $sql = $connection-&gt;prepare("UPDATE posts SET rate = :max_rate, clicks = :total_clicks WHERE id = :id");
          $sql-&gt;bindParam(':id', $id, PDO::PARAM_INT); 
          $sql-&gt;bindParam(':max_rate', $max_rate, PDO::PARAM_INT);
          $sql-&gt;bindParam(':total_clicks', $total_clicks, PDO::PARAM_INT);
          if ($sql-&gt;execute()) {
              header('Location: ../index.php');
          } else { 
              echo "Error updating record: " . $e-&gt;getMessage();
          }
      }
      catch(PDOException $e) {
          echo "Error: " . $e-&gt;getMessage();
      }
  $connection = null;
  ?&gt;
  </code></pre>
  
  <p>Regards.</p>