users_statistics SET money_spent_ad = money+spent_ad + $moneySpent WHERE id_user = 1");
$moneyNow = $mysqli->query("SELECT money FROM users_statistics WHERE id_user = 1 LIMIT 1");
$points = ((int)$moneyNow - ($moneyNow - $moneySpent)) * 0.5;
$mysqli->query("INSERT INTO contest_points (points, id_user) VALUES ($points, 1) ON DUPLICATE KEY UPDATE points = points + $points");
$mysqli->commit();
}catch( Exception $e ){
$mysqli->rollback();
}
$mysqli->commit();
или так
$mysqli->autocommit(FALSE);
try{
$moneySpent = 100;
$mysqli->query("UPDATE users_statistics SET money_spent_ad = money+spent_ad + $moneySpent WHERE id_user = 1");
$moneyNow = $mysqli->query("SELECT money FROM users_statistics WHERE id_user = 1 LIMIT 1");
$points = ((int)$moneyNow - ($moneyNow - $moneySpent)) * 0.5;
$mysqli->query("INSERT INTO contest_points (points, id_user) VALUES ($points, 1) ON DUPLICATE KEY UPDATE points = points + $points");
$mysqli->commit();
}catch( Exception $e ){
$mysqli->rollback();
}
$mysqli->commit();
?
Оставь так
Обсуждают сегодня