Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Check if value exist in mysql

    PHP Code:
    $sql mysql_query("SELECT email FROM users WHERE email ='$email'");
                                        
    if(
    mysql_num_rows($sql) != 0)
    {
    echo 
    '<font color="ff0000"><li> Email exist!</font>';

    So my problem is, that even if i write an email that i know exist in the database it let me through. I got the config.php include a bit up in the code so the database connection is no problem.

    //Zubat

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    mysql_num_rows returns the number of rows or false. The docs. So you should test against > 0.

    NB
    The mysql library is deprecated - there is a stark warning against its use on the docs page - and will be removed in the future.
    The font tag is obsolete.
    Your LI tag is not closed properly, so your HTML is mal-formed.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    A better way:

    PHP Code:
    is_resource($q); 
    $q being the results from the query


  •  

    Posting Permissions

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