[thelist] sql for mailing list verify

James Mclean james at adam.com.au
Thu Jul 25 20:29:01 CDT 2002


Hi,

> I have a mailing list that people can add themselves to.  I need to verify
> if the email address already exists in the database before adding them to
> the mailing list.  Is there a simple way to use SQL for this?
>
> Something like 'IF NOT EXISTS 'bob at hotmail.com' THEN INSERT...etc'

In PHP.

$sql = "SELECT email FROM table WHERE email='$email';
$qu = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($qu)) {
    $sql2 = "INSERT INTO table (email) VALUES ('$email')";
    $qu2 = mysql_query($sql2) or die(mysql_error());
} else {

    print"Sorry, email exists";
}

Regards,

James Mclean




More information about the thelist mailing list