3
I have two tables, one for users, and one for validation codes.
I do a code check in PHP and need to do a query in the validation table at the same time that I update this table disabling this code so that it is not validated again, and activate the user if the code is correct.
So I’m doing the update this way:
UPDATE `verificaconta` as `verif`
INNER JOIN `sysusuarios` as `usuarios` ON `usuarios`.`cod` = `verif`.`cod`
SET `verif`.`ativo` = '0', `usuarios`.`ativo` ='1'
WHERE `verif`.`codvalidacao` = ?'
And I was returning the following mistake:
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and Reconnect.
I googled and advised to use: SET SQL_SAFE_UPDATES = 0;
So I did it this way:
SET SQL_SAFE_UPDATES = 0;
UPDATE `verificaconta` as `verif`
INNER JOIN `sysusuarios` as `usuarios` ON `usuarios`.`cod` = `verif`.`cod`
SET `verif`.`ativo` = '0', `usuarios`.`ativo` ='1'
WHERE `verif`.`codvalidacao` = ?'
SET SQL_SAFE_UPDATES = 1;
On my local server, it worked fine, but when I try to run on the web server, it cannot perform the change.
There is another way to perform this update in a single query without having to do a separate update select??
---------- EDIT ----------------
TABLE sysusuarios
VERIFIED TABLE
What is the primary key in each of these tables? You can use them in update? There is a foreign key?
– Felipe Marinho
@Felipemarinho I updated the question with a table print. their only primary key is the ID. But in this case I do not use the ID in these updates, because I have no way of knowing which ID q will be modified.
INNER JOIN
to compare one table with the other? All this is still very confusing for me.– Samanta Silva