Troubles with if else
Posted: Thu Dec 04, 2008 3:03 pm
I'm trying to check $stringData for the string in $look and if found, add the IP to my banned_ip table and quit. Then, every time a request comes in it will check if the IP is in the banned_ip table and if not, it will add the values into testtable.
I can get it to check the string for $look and add the IP to the banned_ip table perfectly fine. But when I try to have it check the banned_ip before adding to testtable the whole thing fails. Please, I have been working on this for a while and it's my first venture into php. I'm sure my code looks horrible :0
I can get it to check the string for $look and add the IP to the banned_ip table perfectly fine. But when I try to have it check the banned_ip before adding to testtable the whole thing fails. Please, I have been working on this for a while and it's my first venture into php. I'm sure my code looks horrible :0
Code: Select all
$stringData = $_REQUEST["id"];
$look = "http://www.site.com";
$pos = strpos($look, $stringData);
if ($pos !== false)
$sqlCheckForDuplicate = "SELECT * from banned_ip WHERE ip = '". $ip ."'";
$result = mysql_query($sqlCheckForDuplicate) or die(mysql_error());
if(mysql_num_rows($result)>0)
{
$feedback[] = '';
}
else
{
$query = "INSERT INTO banned_ip VALUES ('','$ip')";
mysql_query($query);
mysql_close();
}
// BELOW THIS IT DOES NOT WORK
$sqlCheckForDuplicate = "SELECT * from banned_ip WHERE ip = '". $ip ."'";
$result = mysql_query($sqlCheckForDuplicate) or die(mysql_error());
if(mysql_num_rows($result)>0)
{
$feedback[] = '';
}
else
{
$query = "INSERT INTO testtable VALUES ('','$ip','$time','$agent','$stringData')";
mysql_query($query);
mysql_close();
}