Thread: Querying

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    53
    Rep Power
    15
    How would I check wether a email addy already exists in the database?? the table name is members
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    just issue a simple query like this.

    "SELECT * FROM members WHERE email='shiju@post.com'"

    if return value is greater than 0 then the email address is existing in the database.else , not existing in the database.




    ------------------
    SR -
    shiju.dreamcenter.net
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    53
    Rep Power
    15
    WEll could u give me the entire code?? czo thats where i was having a problem..u know something which i could jsut cut-n-paste...my table name is members and the email addy variable whioch the user has inputed is $email or email. Thanx
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Hope the following may work for you..



    $con=mysql_connect('localhost','username','password');

    mysql_select_db ('databasename',$con);

    $result = mysql_query("SELECT * FROM members WHERE email='$email'",$con);

    if (mysql_num_rows($result) == 1)
    {
    # email is existing in the database
    $emailexists = 1;
    }else{
    #Email is not existing...
    exit;
    }

    GOOD LUCK!!


    ------------------
    SR -
    shiju.dreamcenter.net
  8. #5
  9. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    thane
    Posts
    50
    Rep Power
    0
    shiju the code presented by you will work fine but why

    "select * from member where email=$email";

    can't it be just simple like

    $result="select count(email) as xyz from member where email=$email";

    $xyz=mysql_result($result,0,"xyz");

    if($xyz)
    {
    echo "user email exists allready";
    //or do whatever
    }
    else
    {
    echo "user available";
    //ur processing
    }


    ranjeet


  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Ranjeet,

    "select email from member where email=$email";

    this query will return the no of rows.if no of rows is greater 0 then offcourse the email is existing.

    see.. for easy understanding i written that very straight.

    What you are writing also is very fine.But you are doing that in different way.

    Thank You.











    ------------------
    SR -
    shiju.dreamcenter.net
  12. #7
  13. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    thane
    Posts
    50
    Rep Power
    0
    yes sir very true

    but in ur reply u had given

    "select * from member where email=$email";

    instead of

    "select email from member where email=$email"

    that's why i replied in diff way
    ne way thanx
    ranjeet

Similar Threads

  1. Querying for sports info
    By lounatic77 in forum PHP Development
    Replies: 12
    Last Post: January 16th, 2004, 06:49 PM
  2. querying within MySQL or PHP
    By wivellJ in forum MySQL Help
    Replies: 2
    Last Post: September 19th, 2003, 06:47 AM
  3. let brower display something while querying database
    By jerry818 in forum PHP Development
    Replies: 1
    Last Post: September 5th, 2003, 05:53 PM
  4. querying from a tabbed text file - how?
    By spyghost in forum MySQL Help
    Replies: 2
    Last Post: August 31st, 2003, 07:16 PM
  5. Querying accross databases
    By cresswelln in forum PostgreSQL Help
    Replies: 2
    Last Post: February 10th, 2002, 11:41 AM

IMN logo majestic logo threadwatch logo seochat tools logo