Do not Enter Equal Values PHP and MYSQL [closed]

2

I have a script in PHP and MySQL that looks in the client table for all clients that have not yet been imported to another bank / table and it imports.

In the customer table, you have flag imported with values (0 or 1).

I make a select in it and import it into another table bank.

After that, in the same database that has the customer table, there is a table of logs where the email that was imported and the date is inserted.

But sometimes it puts duplicate logs as if it had been imported twice.

I do not want it to take the risk of importing or actually entering twice the same log.

You may ask, ah, just put the email field as unique.

I can not do this, because my system sometimes inserts other types of email client logs, so it would be a problem.

What would be the best solution for this?

    
asked by anonymous 01.11.2016 / 10:46

1 answer

2

Well, you did not pass the table structure, but if you need some more specific detail, you'd better put that part in.

With what you have, you can do the following to test if there is email with the same cliete and same logo type. Aether according to your need.

IF NOT EXISTS (SELECT 1 FROM logs WHERE email ='[email protected]' and idcliente = 1 and idtipolog = 1)
BEGIN
    INSERT INTO logs (idcliente, idtipolog , email ) VALUES(1,1, '[email protected]');
END
    
01.11.2016 / 12:33