SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Threaded View

  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Prevent Duplicate Entries Into Database

    Hi,

    I have a piece of code which checks if an email address is already in the database. However what ever I try I cant get it to prevent a duplicate entry from entering the database.

    Is there a piece of code which stops entries into a database if there are duplicates?

    PHP Code:
        $query mysql_query("SELECT * FROM users WHERE email  = '"$email ."'"); 
    $emailduplicate null;
    if (
    mysql_num_rows($query) > 0

    $emailduplicate 'Email Address is Already in Use.  Please <a href="http://www.website.com/test/activation.php?userid=Y">Retrieve Your Password</a>.'
    }       

              if 
              (
    $registerPassword === $email)  {
                
    $errors['emailalreadyinuse'] = 'You cannot join.';             
            }   
            
            
            
    if(!
    $errors){
    $registerPassword md5($registerPassword);
    $query "INSERT INTO users (usertype, usertypelink, activationcode, firstname, surname, email, password, logo, date_registered) VALUES ('" $usertype "', '" $usertypelink "', '" . ($activationcode) . "', '" $firstname "', '" $surname "', '" mysql_real_escape_string($registerEmail) . "', '"$registerPassword ."', '"$logo ."', NOW())";


                             
         
    $result mysql_query($query); // remove the or die(mysql_error()) code after you resolve the error
         
    if($result){
              
    $success['register'] = '
              
              
              Thank you for registering with website.com.<br>
              You will soon receive a confirmation email. Please click the confirmation link.<br><br>'

    Last edited by SpacePhoenix; Dec 27, 2012 at 01:16. Reason: placed php tags around php code


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
  •