hi, i just need some help, i hope someone could help me, thank u.

i just need to add some conditions but i dont know how, my main point here is if the data already exists then it will update if not then insert, thank u.

include "connect.php";

$amount = $_POST['ct_amount'];

$id = $_SESSION['editId'];

$msg = [];

$sql = "INSERT INTO `ct_trans`(`ct_amount`,`ct_client_id`,`ct_description`) VALUES ('$amount','$id','DEPOSIT');";
if ($db->query($sql) == true){
$sql2 = "SELECT `cu_currentbal`,`cu_client_id` FROM `ct_update` WHERE `cu_client_id` = '$id';";
if ($db->query($sql2) == true){
$sql3 = "INSERT INTO `ct_update`(`cu_currentbal`,`cu_client_id`) VALUES ('$amount','$id');";
if ($db->query($sql3) == true){
$sql1 = "UPDATE ct_update SET cu_currentbal = cu_currentbal + $amount WHERE `cu_client_id` = '$id';";
if ($db->query($sql1) == true){
    $msg['status'] = true;
    $msg['message'] = "Money Deposited Successfully";
}else {
    $msg['status'] = false;
    $msg['message'] = "Failed to Deposit Money";

echo json_encode($msg);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.