Hi, I'm new to the trigger and I have a problem. I have a table with 2 fields | quantity | criteria | and I need that when updating the amount the trigger updates the criterion: example if I update the amount to > 0 then which criterion is updated to Won, if quantity = 0 then criterion that updates to Lost and if quantity is empty then criterion passes to pending.
<?php
$id_mercado = $_POST['id_mercado'];
$cantidad = $_POST['cantidad'];
$criterio = $_POST['criterio'];
$sql = $mysqli->query("UPDATE mercado SET cantidad='$cantidad', criterio='$criterio' WHERE id_mercado=$id_mercado");
?>
the trigger I have is this
CREATE TRIGGER estado_update BEFORE UPDATE ON mercado FOR EACH ROW BEGIN if new.cantidad > 0 then update mercado SET criterio = 'Ganó'; end if; END;
I have not been able to do with the nested if and I do not know how to properly extructure the code, the trigger believes it in phpmyadmin, someone can guide me.