Home:ALL Converter>mysql check entry from another table before insert

mysql check entry from another table before insert

Ask Time:2013-07-31T04:16:10         Author:raindrop

Json Formatter

I have this script add new users to MySql andnow I have created secondary Mysql table for black-list name. so I want MySql check the black-list name before allow insert the data.

$all = implode(",",$_POST);
$all = explode(",",$all);

$insert = "INSERT INTO name VALUES (";  
for ($x=0;$x<5;$x++) 
{
    $all[$x] = clean($all[$x]);
    if ($all[$x] == "" || strlen($all[$x]) > 300)
    die("<p>Please fill in the whole form." . $x);

    $insert .= "'" . $all[$x] . "',";
}

$insert .= "'')";
$res = @mysql_query($insert) ;

I have change to

$insert = "INSERT INTO name VALUES (";  
for ($x=0;$x<5;$x++) NOT IN (SELECT `blacklist` FROM `exclude`)

but didn't get what I am looking for. how I can fix that?

Author:raindrop,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/17956544/mysql-check-entry-from-another-table-before-insert
RiggsFolly :

AS far as I am aware you are going to have to do a seperate select on your exclude table using whatever is the key to that table that is shared with the name table to check this user is not in the exclude list.\nThere is no INSERT syntax to allow a concept like INSERT unless something exists within another table.",
2013-07-30T20:52:19
yy