This is a part of a small banishment system reposed on the value of the $var
how's equal to $_GET['id']
the problem occurred when i attempt to test the code, in the first execution with a false value of $_GET['id'] (not_numeric or <= 0) the code insert correctly the ip in the table but he increment the attempt value by 1, knowing that (attempt) is int(11) in my table without AUTO-INCREMENT or special property so i found the row in the table like this :
id : 1, ip : 192.168.1.X, attempt : 2
id : 1, ip : 192.168.1.X, attempt : 4 (in the second execution of a false value of $_GET['id'])
id : 1, ip : 192.168.1.X, attempt : 6 (in the third execution of a false value of $_GET['id'])
and so on, its always incremented BY 2.
<?php
$ip="192.168.1.11";
$var=1;
if(isset($var))
{
if(is_numeric($var) AND $var >=1)
{
$var=$var;
}
else
{
$var=null;
$msg[]="::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
$query="SELECT * FROM table WHERE ip = '$ip'";
if(($result=$mysql_link->query($query)) AND ($result->num_rows > 0))
{
$row = $result->fetch_assoc();
$current_score_of_attmpt=$row['attempt'];
$new_score_of_attmpt=$current_score_of_attmpt+1;
$result->free();
$query = "UPDATE table SET attempt = attempt +1 WHERE ip = '$ip'";
if($mysql_link->query($query)===TRUE) {
$msg[]="We have Updated your score of attempt to $new_score_of_attmpt";
$msg[]="::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
}
else
{
echo "Update Error: ".$query."<br>".$mysql_link->error;
}
}
elseif(!($mysql_link->error))
{
$query ="INSERT INTO table (ip, attempt) VALUES ('$ip', 1)";
if($mysqli_link->query($query)===TRUE)
{
$msg[]="Its Your First Attempt";
}
else
{
echo "Update Error: ".$query."<br>".$mysql_link->error;
}
}
else
{
echo "SELECT Error: ".$query."<br>".$mysql_link->error;
}
}
}
else
{
$var=null;
}
echo "<br> the value of var = ".$var;
if(isset($msg))
{
for($i=1; $i<=sizeof($msg); $i++)
{
echo "<br>".$i.") ".$msg[$i];
}
}