Do Not Insert PHP and MYSQL Equal Values

Asked

Viewed 88 times

2

I have a PHP and Mysql script that searches the client table for all clients that have not yet been imported to another database/table and imports.

In the customer table, there’s a flag imported with values (0 or 1).

I make a select on it and import to another table bank.

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

Only sometimes it puts duplicate logs, as if it had mattered twice.

I don’t want it to occur the risk of importing or actually entering twice the same log.

You can ask, ah, just put the email field as single.

I can’t do that because my system sometimes inserts other types of logs with client email so it would give problem.

What better solution to this?

  • Have you thought about using composite primary key? Read about it and maybe for your project. Composite Primary Key

  • Post the structure of your log table.

1 answer

2

Well, you didn’t pass the table structure, but in case you need some more specific detail, you’d better post that part.

With what you have, you can do the following to test if there is email with the same cliete and same type of logo. Land as 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.