Link to home
Start Free TrialLog in
Avatar of jcw20
jcw20Flag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of TeRReF
TeRReF
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jcw20

ASKER

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)
Avatar of jcw20

ASKER

<?php
$host="10.10.10.4"; // 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')";
$result=mysql_query($sql);

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

else {
echo "ERROR";
}

mysql_close();
?>