i have this code :
<?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>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);
}
}
?>
where have been i going wrong ? :O
because either it only adds for first time and then whenever the ip changes it doesnt.
I have modified the code below for improved layout, descriptive variable names, added debugging, suggested logic improvements which simplify the code and fixed your bug.
Please read and try to use some of this in your future code, it will help you immensely with debugging or just writing code people can understand. I not trying to sound like an condescending ass, we all started somewhere, and I still make silly mistakes!
If there is something I have done you do not understand (either the code, or why I did it that way) please ask.