Good day, I am trying to execute a query where every time I execute it, I subtract 1 from an entire field of a MySQL table. When executing the pure query from phpmyadmin, I correctly subtract 1, but when executing the url from localhost, I subtract the amount of 2. Does anyone know why it will be? This is my query:
<?php
require "conn.php";
$id_fechas = $_GET["id_fechas"];
$sql="UPDATE fechas SET cupos_disponibles = cupos_disponibles -'1' WHERE id_fechas = '$id_fechas'";
mysqli_query ($mysqli, $sql);
if ($mysqli->query($sql)) {
echo "Actualiza";
} else {
echo "Error updating record: " . $mysqli->error;
}
mysqli_close($mysqli);
?>
You are executing the query twice:
Another option would be to use a variable to store the result of the query: