I would like to save data to database only once per user, based on his/her IP address. I have a database with the url, date, time and ip list. How can I check if ip already exist and if not – insert data to database, otherwise do nothing? Here’s my code so far:
<Check if IP already exists in the database - if no - insert:>
$query = "INSERT INTO link (url, date, time, ip) VALUES ('$ref','$date','$time', '$someip')";
mysql_query($query) or die('Error, insert query failed');
}
else {
echo 'This ip already exists';
}
Query your database for a row with a matching ip. You can then use mysql_num_rows to determine how many rows were returned.
127.0.0.1should obviously be a variable. You can get a users ip with$_SERVER['REMOTE_ADDR'].