O-Trap
I'm trying to set up a script (Where's Ender when you need him?) that checks a visitor's IP address again a database. If it's not already in the database, the script adds it. If it is already in there, it does something else.
I had this sometime before, but I don't remember how the database was set up. Here's what I had:
[PHP]
<?php
$username = "mysql_username";
$password = "password";
$hostname = "localhost";
$ip = $_SERVER['REMOTE_ADDR'];
$short = ip2long($ip);
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$dbname = mysql_select_db(mysql_database, $dbhandle) or die("Cannot find the database");
$result = mysql_query("SELECT NULL FROM table WHERE column='$short'");
if(mysql_num_rows($result)) {
echo "Baha! You've been here before!";
} else {
mysql_query("INSERT INTO table (column) VALUES (" . $short . ")");
echo "$ip is now $short";
mysql_close($dbhandle);
}
?>
[/PHP]
Anyone know how the table should be setup?