PHP ip logger error
<p>i have this code :</p>

<pre><code>   &lt;?php
    echo $_POST['id-input'];
    $time = time();
    $ip=$_SERVER['REMOTE_ADDR'];
    $userid_c = $_POST['id-input'];
    $con = mysql_connect("localhost","username","password");
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }

     mysql_select_db("kritya20_data", $con);
     $sql = "SELECT * FROM users_online WHERE user_id='$userid_c'";
     $query = mysql_query($sql);
     $rows_only_c = mysql_num_rows($query);
     if($rows_only_c == 0)
     {
        $sql1= "INSERT INTO users_online (user_id , online_since , lastup , lobbieid)
        VALUES ('$userid_c' , '$time' , '$time' , '1')";
        $query1 = mysql_query($sql1);
     }
     elseif($rows_only_c==1)
     {
        $sql2 = "UPDATE users_online
        SET lastup='$time'
        WHERE user_id='$userid_c' ";
        $query2 = mysql_query($sql2);
     }
     $sql3 = "SELECT * FROM iptable WHERE user_id='$userid_c'";
     $query3 = mysql_query($sql3);
     $row_ip = mysql_num_rows($query3);
     if($row_ip==0)
     {
          $sql4 = "INSERT INTO iptable (user_id , ip , added)
          VALUES ('$userid_c' , '$ip' , '$time')";
          $query4= mysql_query($sql4);
    }
    elseif($row_ip&gt;0)
    {
        $mt=0;
        $mf=0;
        $sql4 = "SELECT * FROM iptable WHERE user_id='$userid_c'";
        $query4 = mysql_query($sql4);
        while($row=$query4)
        {
          if($ip==$row[2])
          {
              $mt++;
          }
          else
          {
              $mf++;
          }
        }
        if($mf!=0)
        {
            $sql5 = "INSERT INTO iptable (user_id , ip , added)
            VALUES ('$userid_c' , '$ip' , '$time')";
            $query5= mysql_query($sql5);
        }
    }
?&gt;
</code></pre>

<p>where have been i going wrong ? :O
because either it only adds for first time and then whenever the ip changes it doesnt.</p>
