<?php
$db = mysqli_connect("localhost", "root", "", "paypal");
/* verificar la conexión */
if (mysqli_connect_errno()) {
die("Conexión fallida:" . mysqli_connect_error());
}
$sq = "INSERT INTO montos (usuario, monto) VALUES ('Andres', (SELECT SUM(monto ) montos FROM datos WHERE id IN (1,2)) )";
$result = mysqli_query($db, $sq);
if ($result > 0 ) {
$sql = mysqli_query($db,"UPDATE datos SET monto = monto - 50 WHERE id = 2 ");
}
?>
I want to know if I can join the two queries to make a general query the first sum and the other makes a subtraction and updates the field that is being used.