Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Use mysql and ph record uniqe ip address

Posted on 2006-06-30
6
260 Views
Last Modified: 2011-10-03
i want to add this to my curent guest book essboork but only record it if it is uniqe
0
Comment
Question by:jcw20
  • 2
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
TeRReF earned 250 total points
ID: 17020373
Euh... do you mind clearifying your question a bit?

You can retrieve someone's ip-address with
$ip = $_SERVER["SERVER_ADDR"];

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?!
0
 
LVL 1

Author Comment

by:jcw20
ID: 17020876
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
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17021018
You should use varchar(15) and do a string comparison in a query (like the query I showed you)
0
 
LVL 1

Author Comment

by:jcw20
ID: 17021082
<?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();
?>
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question