PDO::ERRMODE_EXCEPTION, ]); // garantir colunas (ignora se já existirem) $db->exec("ALTER TABLE contadores ADD COLUMN IF NOT EXISTS entradas_total INT NOT NULL DEFAULT 0"); $db->exec("ALTER TABLE contadores ADD COLUMN IF NOT EXISTS saidas_total INT NOT NULL DEFAULT 0"); $uid = $_POST['uid'] ?? ''; if ($uid === '') { header("Location: /console.php?ok=err"); exit; } $stmt = $db->prepare(" UPDATE contadores SET entradas_total = COALESCE(entradas_total,0) + COALESCE(entradas,0), saidas_total = COALESCE(saidas_total,0) + COALESCE(saidas,0), entradas = 0, saidas = 0 WHERE uid = :uid "); $stmt->execute(['uid' => $uid]); header("Location: /console.php?ok=line"); exit; } catch (Throwable $e) { header("Location: /console.php?ok=err"); exit; }