SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2001
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    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.
    Thanks
    assignedHelp Me: How to check if data already exists.
    Last edited by Assigned; Dec 11, 2001 at 11:54.

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    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;

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

    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: http://www.hotscripts.com/Detailed/8799.html - this does pretty extensive IP logging


Bookmarks

Posting Permissions

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