SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a simple form that has one field:

    email

    And my forms action is: email.php

    In email.php, i just insert the email address to a table called:

    site

    and a database called:

    petesmc_misc



    What i want to know is, using PHP how can i check for a duplicate value in the table before trying to insert. If i insert then the user would get the message:

    You could not be added: Duplicate value, "test@test.com" for Key 1

    Is there a way i can check first then say if it is duplicate?

    Thanx

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pete wouldn't it be better to not have the email field as a unique key, instead make auto-increment id field then when you want to access the list of emails you can use SELECT DISTINCT email from site; Instead of running two queries to see if they are already in there? But if you want the long way

    $result = mysql_query("SELECT email from site where email = '$email'");
    if (mysql_num_rows($result) > 0) {
    print "Email already in db";
    }
    else {
    //insert query here
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx allot


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
  •