Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8071741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:47:18+00:00 2026-06-05T13:47:18+00:00

I am going to be logging the IP addresses that my users log in

  • 0

I am going to be logging the IP addresses that my users log in with. To do this, I have a simple table with 3 columns: user, ip, time. time is the time at which they last logged in with that address.

When they log in, I want to insert a row into the database containing the IP they logged in with, and the time they logged in.

If a row with the same user AND same ip already exists, I just want to update the time. A more general question:

How can I INSERT a row, or UPDATE it if two (or more) of its columns are the same?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:47:20+00:00Added an answer on June 5, 2026 at 1:47 pm

    You just need to create composite unique key user + ip and use INSERT ON DUPLICATE KEY UPDATE

    INSERT INTO tbl (user, ip, `time`) VALUES (1, '1.2.3.4', NOW())
    ON DUPLICATE KEY UPDATE `time` = NOW()
    

    To create index use something like

    CREATE UNIQUE INDEX tbl_user_ip ON tbl (user, ip)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom logging function to log to the firebug console that looks
So, I have a website that figures out the users location when they load
I have a website that requires some secure pages for logging in, user accounts,
Going mad now. I have a MVC solution that i've upgraded from MVC 1
Going through the microsoft authentication tutorial listed here they have you create a master
hey guys i have written a small webservice which allows users of a company
I made a dead simple Console class in AS3 that allows logging to be
I have a site that is going to use Wordpress within the main server
We have a C# logging class that uses System.Diagnostics.StackTrace and StackFrame to obtain information
I'm creating a database that is going to be logging PC usage. There will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.