Populate an Array from MYSQL and check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidPr
    New Member
    • Mar 2007
    • 155

    #1

    Populate an Array from MYSQL and check

    I have a website that requires a visitor to register in order to make a post. I have one or two users that are violating the terms and every day I'm having to delete them. They just re-register, sometimes using a new email address (always a gmail account though).

    I want to create a database and enter banned email addresses. Then I want to populate an array using these banned email addresses. When someone tries to register I want to check to see if the email address they're using is in the banned email array, if so the registration will fail.

    I can make the database and put the information in it OK, but I'm not familiar with arrays and don't know how to write the code to populate an array from a database or how to write the query to check to see if the email is in the array. Can someone help me with this?

    Thanks
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You would just do a simple SELECT query using a WHERE clause.

    Code:
    $email = "bademail@gmail.com";
    
    // Query searches the database for an entry that has matching emails.
    $sql = "SELECT `email` FROM `bad_emails` WHERE `email` = '{$email}' LIMIT 1";
    
    $res = mysql_query( $sql );
    
    if ( mysql_num_rows( $res ) > 0 )
    {
        die ( "Banned email." );
    }
    else
    {
        // good email.
    }
    However, they could just sign up with a new email address. You might look into banning IP addresses, although even that isn't reliable.

    - mark.

    Comment

    Working...