how to insert the ip address if it not exists in current dat

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
theultimateboss
Forum Newbie
Posts: 2
Joined: Fri Nov 07, 2008 6:32 am

how to insert the ip address if it not exists in current dat

Post by theultimateboss »

Hi All;

I am new to this forum.

Can anybody let me know, how to insert the ip address and date into mysql table, if the ip address didnt store into current date.

insert the date & ip address if the ip not exists in current date else not store.

can any body know to write the mysql query plz let me know. I need to write for storing daily hits in my site.

Thanks in advance....
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: how to insert the ip address if it not exists in current dat

Post by Hannes2k »

Hi,
one solution would be to set the ip column to unique, so you get an error if you try to insert the same ip twice.

An other solution would be just using SELECT before you insert the new row.
theultimateboss
Forum Newbie
Posts: 2
Joined: Fri Nov 07, 2008 6:32 am

Re: how to insert the ip address if it not exists in current dat

Post by theultimateboss »

I already did ur first option. If we use the first method, once the ip will be stored into our database, then it will never store. The user may be come to again oour site after 2 days. Then his ip wont store.

So, the 2nd option is better I think. But How to select the ip from database and compare to date whether it present or not.

I cant get it,

If u can get plz let me know...

Thanks...
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to insert the ip address if it not exists in current dat

Post by VladSun »

Hannes2k wrote:one solution would be to set the ip column to unique, so you get an error if you try to insert the same ip twice.
theultimateboss wrote:I already did ur first option. If we use the first method, once the ip will be stored into our database, then it will never store. The user may be come to again oour site after 2 days. Then his ip wont store.

One could always define unique constraint or even primary key based on two columns ;)
There are 10 types of people in this world, those who understand binary and those who don't
oddsmojo
Forum Newbie
Posts: 6
Joined: Thu Nov 06, 2008 9:23 am

Re: how to insert the ip address if it not exists in current dat

Post by oddsmojo »

I used to be in your shoes... The first step to a learning curve is always the hardest... I learned PHP/MYSQL through phpmyAdmin. Use the tool to insert the data for you once. Then you will notice a link called Create PHP Code where it will write the query for you based on how you inserted your data. It is a great tool and can be very valuable for learning PHP/MYSQL.

Another solution would be to dig through forums where other people are having problems. Read through how they fixed them. There is great incite (and maybe insanity) to be had through forum reading.

.02

Good luck!

Robert
Post Reply