Home:ALL Converter>mysql insert and check not on blacklist table

mysql insert and check not on blacklist table

Ask Time:2013-05-25T00:56:49         Author:TrivoXx

Json Formatter

Hi i want to make an insert in my mysql database but first I want to check if the email is not avaible in the table blacklist. If the mail is in the blacklist I want to ignore the insert.

$sqlinsertqueue = "
INSERT INTO queue Set
email = '$email'"
mysql_query($sqlinsertqueue,$db);

My blacklist has also the field email. My tablename from my blacklist is blacklist.

Author:TrivoXx,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/16740038/mysql-insert-and-check-not-on-blacklist-table
Joachim Isaksson :

Since @EdGibbs deleted his answer before I got to say this, he was on the right track with an INSERT ... SELECT;\n\nINSERT INTO queue (email) \n SELECT '[email protected]' FROM DUAL\n WHERE '[email protected]' NOT IN (SELECT email from Blacklist);\n\n\nAn SQLfiddle to test with.\n\nYou may want to use PDO or MySQLi instead of the deprecated mysql_* api, or at the very least do mysql_escape_string() on the email addresses before inserting them into the SQL query.",
2013-05-24T17:23:37
yy