title: Voting-system wont pass on vote to database
body: <p>I'm having difficulties on debugging why this voting-script I'm trying to adapt wont update the vote count and register the user's IP-address in the database. As of now neither of the two things seem to be working.</p>
  
  <p>The script consists of:</p>
  
  <p><strong>Index.php</strong>:</p>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  $(function() {
  
  $(".vote").click(function() 
  {
  
  var id = $(this).attr("id");
  var name = $(this).attr("name");
  var dataString = 'id='+ id ;
  var parent = $(this);
  
  
  if(name=='up')
  {
  
  $(this).fadeIn(200).html('');
  $.ajax({
     type: "POST",
     url: "up.php",
     data: dataString,
     cache: false,
  
     success: function(html)
     {
      parent.html(html);
  
    }  });
  
  }
  else
  {
  
  $(this).fadeIn(200).html('');
  $.ajax({
     type: "POST",
     url: "down.php",
     data: dataString,
     cache: false,
  
     success: function(html)
     {
         parent.html(html);
    }
  
   });
  
  
  }
  
  
  
  
      });
  
  });
  &lt;/script&gt;
  &lt;style type="text/css"&gt;
  #main{
  height:auto;
  margin:0 auto;
  width:500px;
  margin-bottom: 10px;
  }
  .clearfix{
  clear:both;
  }
  #left{
  float:left;
  width:40px;
  height:auto;
  text-align:center;
  }
  #message{
  float:right;
  width:460px;
  height:auto;
  margin-top: 14px;
  font-family:Arial, Helvetica, sans-serif;
  font-size:12px;
  font-weight:bold;
  }
  .up{
  background-image:url(up.png);
  }
  &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;?php
  error_reporting(E_ALL);
        ini_set('display_errors', '1');
  include('config.php');
  $sql=mysql_query("SELECT * FROM messages");
  while($row=mysql_fetch_array($sql))
  {
  $message=$row['msg'];
  $mes_id=$row['mes_id'];
  $totalvotes=$row['totalvotes'];
  ?&gt;
  &lt;div id="main"&gt;
      &lt;div id="left"&gt;
      &lt;span class='up'&gt;&lt;a href="" class="vote" id="&lt;?php echo $mes_id; ?&gt;" name="up"&gt;&lt;img src="up.png" alt="Down" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
      &lt;?php echo $totalvotes ?&gt;&lt;br /&gt;
      &lt;span class='down'&gt;&lt;a href="" class="vote" id="&lt;?php echo $mes_id; ?&gt;" name="down"&gt;&lt;img src="down.png" alt="Down" /&gt;&lt;/a&gt;&lt;/span&gt;
      &lt;/div&gt;
      &lt;div id="message"&gt;
          &lt;?php echo $message ?&gt;
      &lt;/div&gt;
      &lt;div class="clearfix"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;?php } ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And <strong>up.php</strong> and <strong>down.php</strong>  that is similar except from the add/subtract part in the sql command.</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
              ini_set('display_errors', '1');
  
  include("config.php");
  
  
  $ip=$_SERVER['REMOTE_ADDR']; 
  
  $id=$_POST['id'];
  $id = mysql_escape_String($id);
  
  $ip_sql=mysql_query("SELECT ip_add FROM voting_ip WHERE mes_id_fk='$id' AND ip_add='$ip'");
  $count=mysql_num_rows($ip_sql);
  
  if($count==0)
  {
  $sql = "UPDATE messages SET totalvotes=sum(totalvotes+1) WHERE mes_id='$id'";
  mysql_query($sql);
  
  $sql_in = "INSERT INTO voting_ip (mes_id_fk,ip_add) VALUES ('$id','$ip')";
  mysql_query($sql_in);
  
  
  
  }
  else
  {
  }
  
  ?&gt;
  </code></pre>
  
  <p>Online link here: <a href="http://itu.dk/people/mbaj/dwdeksamen/voting/voting/" rel="nofollow">http://itu.dk/people/mbaj/dwdeksamen/voting/voting/</a></p>
  
  <p>Thanks in advance.</p>