Search For Duplicate Entries In A Database

Discussion in 'Databases' started by SEMSpot, Aug 5, 2008.

  1. #1
    I have a landing page where I would like to save the user's information, however before checking to see if each field has been filled out properly I would like to take there email address and have it search the database to see if it is already in there. However I am stuck with this little problem and need a little help.

    
    $search_email = "SELECT email FROM db where email = $email";
    if (mysql_query($search_email)){
    echo 'That email address is already in our system';}
    
    else {
    here is where it verifies the data fields and submits them to the database
    }
    
    
    Code (markup):
    Problem is it will check to make sure each field has been filled out, if they haven't it will kick back with an error message to them. However if everything has been filled out, it will still submit the information to the DB even if that email address was submitted before.

    Any help would be appreciated.
     
    SEMSpot, Aug 5, 2008 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Try the code something like this but don't forget to connect to database :)
    $search_email = "SELECT email FROM db where email = '$email'"; // use single quotes around $email
    $result = mysql_query($search_email);
    if (mysql_num_rows($result)>0)
    {
       echo 'That email address is already in our system';
    }
    else 
    {
    here is where it verifies the data fields and submits them to the database
    }
    Code (markup):
     
    mwasif, Aug 5, 2008 IP
  3. SEMSpot

    SEMSpot Peon

    Messages:
    513
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That does check to see if they address is in the system, however if it is it still goes down through and takes them to the thank you page while displaying "that email address is already in our system" at the very top and then showing the rest of the site below it. It does not actually submit the data though, just shows them the thank you page.
     
    SEMSpot, Aug 5, 2008 IP
  4. SEMSpot

    SEMSpot Peon

    Messages:
    513
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ok problem solved, after my script was done checking everything I had it displaying the thank you page. What I did now was take the echo statement after everything has checked out alright and just displayed the thank you message there. I appreciate the help, it works great now.
     
    SEMSpot, Aug 5, 2008 IP