I am trying to get my If statement to check if the IP address of a user who visits a page matches an IP address in the MySQL database. At the moment, I can see the "Thank you" page as my IP address is the first record in the table. However, I have been using a proxy to test another IP address and it shows me the "Error" page. I think this has something to do with my query array only checking the first record and not the rest.
Here's the PHP code
<?php
require_once 'db.php';
$ip_user = $_SERVER['REMOTE_ADDR'];
$query = "SELECT ip_add FROM signup";
if(!mysql_query($query))
{
echo "<h4>Query failed</h4>";
}
$result = mysql_query($query);
$rec = mysql_fetch_array($result);
if($ip_user == $rec['ip_add'])
{
echo "You can download these ebooks.";
echo "<p>Your IP: $ip_user</p>";
}else {
echo "Trying to get a free ride?";
echo "<p>Your IP: $ip_user</p>";
}
?>

New Topic/Question
Reply




MultiQuote





|