PDA

View Full Version : ip check (if, echo etc... help)


Fronix
09-01-2008, 12:24 PM
Hey well i need some help with the if stuff im trying to get the script to say "This ip is not banned" when the script can't find that ip in teh database, anyone that can help??





<html>
<Head<TITLE>Ip ban check</TITLE></head>
<form action="ipfinder.php" method="post">
</br>
</br>
Enter Youre ip: <input type="text" name="find" size="15">
</br>
</br>
<input type="submit" value="Look!">

</form>
</body>
<textarea name="output" cols="40" rows="1">
<?php
$find = $_POST['find'];
$connect = mysql_connect('localhost', 'root', 'snailzisleet');
$dbsel = mysql_select_db('accounts', $connect);
$query = mysql_query("SELECT * FROM `ipbans` WHERE `ip` = '$find';");
while ($res = mysql_fetch_array($query, MYSQL_ASSOC)){
$ip = $res["ip"];
$expire = $res["expire"];

echo ('IP: "' . $ip . '" has been banned till: "' . $expire . '"');
}
?>
</textarea>
</br>
</br>
</br>
</br>
</html>

edbr
09-02-2008, 01:45 AM
an if statement not confident of the code but try this

if($ip==$find){echo "this ip is banned";}
if($ip!=$find){echo "this ip is not banned";}

davidj
09-02-2008, 06:50 AM
echo ($ip==$find)? "IP is Banned" : "IP is not Banned";

edbr
09-02-2008, 07:11 AM
bagged! new snippet for the cupboard.

Fronix
09-02-2008, 09:16 AM
So it shuld be like this then?



<html>
<form action="ipcheck.php" method="post">
</br>
</br>
Enter Youre ip: <input type="text" name="find" size="15">
</br>
</br>
<input type="submit" value="Look!">

</form>
</body>
<textarea name="output" cols="40" rows="1">
<?php
$find = $_POST['find'];
$connect = mysql_connect('*******', 'root', '****');
$dbsel = mysql_select_db('bfwowacc', $connect);
$query = mysql_query("SELECT * FROM `ipbans` WHERE `ip` = '$find';");
while ($res = mysql_fetch_array($query, MYSQL_ASSOC)){
$ip = $res["ip"];
echo ($ip==$find)? "IP is Banned" : "IP is not Banned";
$expire = $res["expire"];

echo ('IP: "' . $ip . '" has been banned till: "' . $expire . '"');

}
?>
</textarea>
</html>

edbr
09-03-2008, 02:27 AM
try
$expire = $res["expire"];

echo ($ip==$find)? "IP".$ip "is banned till" .$expire : "IP is not Banned";
David?

davidj
09-03-2008, 06:44 AM
that looks right