0

In my database, I have a table of IPs that I have banned from accessing certain things in my PHP script. When I enter my IP into the database (as a string, example "123.4.5.6") and it doesn't seem to echo "banned", when I have clearly entered my IP into the banned database table.

<?php
require_once('config.php');
$ip = $_SERVER['REMOTE_ADDR'];
$checkipban "SELECT * FROM banned WHERE bannedip = '$ip'
";
$banquery = mysql_query($checkipban,$con);
if(mysql_num_rows($banquery) > 0)
echo "banned";
}
?>

$con is the connection to the database in config.php and it works because other MySQL queries in the script work. The database table is called banned and there is only one column called bannedip.

user1008096
  • 535
  • 1
  • 5
  • 5

2 Answers2

3

Seems typo. You missed =

$checkipban = "SELECT * FROM banned WHERE bannedip = '$ip'";
            ^

NOTE:

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Rikesh
  • 26,156
  • 14
  • 79
  • 87
1

You left = for assigning it to varaible $checkipban,

$checkipban  = "SELECT * FROM banned WHERE bannedip = '$ip'";
Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70