php - query result with multiple results with in if else statement -


i'm working on script makes possible allow ip's out of query go website. current problem allow first result of query go through , second result isn't neither rest.

require_once("../mysql.php");  $ip = $_get['ip']; $sql = "select distinct ip servers status = 1"; $res = mysql_query($sql) or die(mysql_error()); $allow = mysql_fetch_assoc($res); if ($ip != $allow['server']) {     echo 'ip not allowed!';     die (); } $port = $_get['port']; 

what doing wrong in case?

you have use while loop like:

$ipallowed = false; while ($allow = mysql_fetch_assoc($res))     if ($ip == $allow['server']) {         echo 'ip allowed!';         $ipallowed = true;         break;     } if (!$ipallowed) {     echo 'ip not allowed!';     die(); } 

or use (faster method):

$sql = "select ip servers status = 1 , ip = '".mysql_real_escape_string($ip)."'"; $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) === 0) {     echo 'ip not allowed!';     die(); } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -