Banning with MySQL

<?php $dbhost='localhost'; $dbusername='*****'; $dbuserpass='*****'; $dbname = 'fusk'; $tblname = 'fuskare'; mysql_connect ($dbhost, $dbusername, $dbuserpass); mysql_select_db($dbname) or die('AHH, Kunde inte ?ppna databas'); $sql="SELECT ip FROM $tblname"; $result=mysql_query($sql); $banned=mysql_num_rows($result); $userip = $_SERVER['REMOTE_ADDR']; if($userip == $banned){ header("Location: blockad.php"); exit(); } ?>

can anyone explain to why this script wont get the ip’s i?ve got in my db?


It probably IS getting the IP’s you have in your DB, but the way you are retrieving them is incorrect. $banned contains only a number of rows that the query returned. You should really look into mysql_fetch_array or mysql_fetch_assoc

Finally please have a look at as it would make things much easier for all concerned.