PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
Yeah, that's how I originally had it but in looking up bits of code I found someone had done it the other way. I'm out of ideas so I figured it was worth a shot and just left it like that. Seems to work the same either way.
$stringData = (int) $_REQUEST["id"];
$look = 'http://www.site.com';
$pos = strpos($look, $stringData);
// this part don't seem to be logic for me
// if you don't want to make query on $pos !== false
// you should take all query process to brackets not only $sqlCheckForDuplicate query
// otherwise your script will just die as on mysql_error()
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[] = NULL;
} else {
$query = "INSERT INTO `banned_ip` VALUES (NULL,'".$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[] = NULL;
} else {
$query = "INSERT INTO `testtable` VALUES (NULL,'".$ip."','".$time."','".$agent."','".$stringData."');";
mysql_query($query);
mysql_close();
}