MySQL query that will just not work, GEOIP
Posted: Sun Oct 26, 2008 6:03 pm
Here is a little script that I CANNOT get to work! It is crazy!
It is a problem with the mysql_fetch_array but I can't understand why. When the page is visited you see: Unknown and no errors at all.
When I run "SELECT * FROM `geo_ip` WHERE '$ipnum' >= `begin_num` AND '$ipnum' <= `end_num`" manually from PhpMyAdmin with my $ipnum it works fine and outputs two rows.
I don't understand why this script doesn't work at all?
I am using the geo_ip database.
Does anyone know what is going on?
It is a problem with the mysql_fetch_array but I can't understand why. When the page is visited you see: Unknown and no errors at all.
When I run "SELECT * FROM `geo_ip` WHERE '$ipnum' >= `begin_num` AND '$ipnum' <= `end_num`" manually from PhpMyAdmin with my $ipnum it works fine and outputs two rows.
I don't understand why this script doesn't work at all?
I am using the geo_ip database.
Does anyone know what is going on?
Code: Select all
function connect_me(){
$DB_USER = 'REMOVED';
$DB_PASSWORD = 'REMOVED';
$DB_HOST = 'REMOVED';
$dbc = mysql_connect ($DB_HOST, $DB_USER, $DB_PASSWORD) or die(mysql_error());
mysql_select_db('REMOVED') or die(mysql_error());
mysql_query("SET NAMES `utf8`") or die(mysql_error());
if($ERROR_REPORTING == 1){ do_error($error,2);}
}
function disconnect_me(){
@mysql_close($dbc);
@mysql_close();
}
function get_country(){
$user_ip = check_ip();
$temp = explode('.',$user_ip);
$ipnum = 16777216*$temp[0] + 65536*$temp[1] + 256*$temp[2] + $temp[3];
$qry = mysql_query("SELECT * FROM `geo_ip` WHERE '$ipnum' >= `begin_num` AND '$ipnum' <= `end_num`") or die(mysql_error());
$get_country = mysql_fetch_array($qry) or die(mysql_error());
if ($get_country['country_name']=="") { return 'Unknown'; } else { return $get_country['country_name'].':'.$get_country['iso_code']; }
}
$country_info = explode(':',get_country());
echo $country_info;
disconnect_me();