Use mysql and ph record uniqe ip address

i want to add this to my curent guest book essboork but only record it if it is uniqe
Who is Participating?
TeRReFConnect With a Mentor Commented:
Euh... do you mind clearifying your question a bit?

You can retrieve someone's ip-address with

You could create a table with ip addresses and query it with the aquired ip addres, something like:
$query = "SELECT COUNT(*) as cnt from ipaddresses where ip=".$ip;

Hope this helps a bit?!
jcw20Author Commented:
Well my goal is to have the guestbook show the ip plus record other info but if that ip has been recorded to not accept the entry but i don't know what kind of field to use in mysql to shw up as a doted decimal  like  1234.1234.1234.1234
You should use varchar(15) and do a string comparison in a query (like the query I showed you)
jcw20Author Commented:
$host=""; // Host name
$username="web"; // Mysql username
$password=""; // Mysql password
$db_name="addressbook"; // Database name
$tbl_name="addressbook"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");

$datetime=date("y-m-d h:i:s"); //date time
$ip = $_POST['ip'];
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$sql="INSERT INTO $tbl_name(ip,name,lastname, email, comment, datetime)VALUES('$ip','$name','$lastname', '$email', '$comment', '$datetime')";

//check if query successful
echo "Successful";
echo "<BR>";
echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page

else {
echo "ERROR";

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.