Forum Moderators: coopster
Anyway, I`m writing (well, attempting to write) a guestbook script and I want to log ip addresses in the database, so ipbanning can be switched on or off. To pass the ip address into the database I`m using:
<input type=\"hidden\" name=\"useraddress\" value=\"REMOTE_ADDR\">
Whats the best syntax to check if the ipaddress exists in the database?
What I`m using is:
if ($_REQUEST['signguestbook']){
$query = "SELECT ipbanning FROM guestbook";
$result = mysql_query($query) or die ("Error, couldn`t connect to Database");
$row = mysql_fetch_array($result);
if ($row['s_ipbanning']){
$query2 = "SELECT ipaddress FROM guestbook";
$result2 = mysql_query($query2) or die ("Error, couldn`t connect to Database");
$row2 = mysql_fetch_array($result2);
$ipcheck = $row2[0];
if ($useraddress == $ipcheck){
echo "Error, you have already signed the guestbook";
guestbookFooter();
exit;
} else {
return false;
}
}
rest of code.....
}
Does that make any sense? Should "return false" even be there? If I do:
$query2 = "SELECT ipaddress FROM guestbook WHERE $useraddress = '$REMOTE_ADDR'";
Does that work?
Thanks for the help!
:)
function ipBanning() {
global $REMOTE_ADDR;$queryipban = "SELECT ipaddress FROM guestbook" or die ("Error, couldn`t connect to Database");
$resqueryipban = mysql_query($queryipban);while ($ip = mysql_fetch_row($resqueryipban))
{
if ($ip["0"] == $REMOTE_ADDR)
{
echo "Error, you have already signed Guestbook";
guestbookFooter();
exit;}
}
return 0;
}
It seems to be working ok.
:)