Search database

I am having trouble with coding a search. Its very basic stuff. I want to search a table to get a match for $ips (which is an IP address).How do I write the if and else statement - one for where the ip address is in the table and another for when it is not

I have used the following code but there are no records in the table so it should not be found


$result = mysql_query("SELECT ip FROM ip WHERE ip='$ips'");

if (!$result) {
echo "Your ip address is accepted";
}
else
{
echo "your website is banned";
}


<?php
$res = mysql_query(sprintf("SELECT ip FROM table WHERE ip = '%s' LIMIT 1;", $ip));

if(1 === mysql_num_rows($res)){
  #ip found
}else{
  #ip not found
}

:slight_smile:

Thanks - that works

BTW what is the difference between === and ==

== compares value, === compares value and type.