SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2001
    0 Post(s)
    0 Thread(s)

    Help me: how to check if data exists

    I am building a mysql db that will be updated by users via a form. However, I don;t want duplicate entries and would like for the user to be notified if the data already exists, if not, add it.
    Also, I would like to capture the IP if every user that adds records to the DB.
    How do I do it? Being a newbie, I would like the code so I can learn from it.
    assignedHelp Me: How to check if data already exists.
    Last edited by Assigned; Dec 11, 2001 at 10:54.

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    0 Post(s)
    0 Thread(s)
    For the first part, if you set the column of the mysql table to be UNIQUE, when someone tries to make a duplicate entry, mysql will stop them and return an error code. Try doing it yourself and capture the output of the function mysql_errno() - it will have a distinct error code (lets say error code is 4321 for example). You can than do something like this;

    $error = mysql_errno();
    if ( $error == 4321 ) {
    echo "That user name is already in use - please try again";

    For the IP logging, take a look at the PHP function "gethostbyaddr". Also take a look at some of the web stats applications out there, e.g. ezBoowebstats: - this does pretty extensive IP logging


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts