i have trouble to update the balance table maybe my coding in sql was wrong. The logic in transaction table "Debet" will mines balance saldo and the transcation "Kredit" will plus balance saldo table. So this is code to add data and update the balance to table balance.
if(isset($_POST['submit'])){
//$id = $_POST['id'];
$uid = $_POST['uid'];
$nominal = $_POST['nominal'];
$jenis = $_POST['jenis'];
$tanggal = $_POST['tanggal'];
$sql = "insert into transaksi(id,uid,nominal,jenis,tanggal)values('','$uid','$nominal',' $jenis',' $tanggal')";
$sql2= "update saldo s INNER JOIN transaksi t ON s.id = t.uid set s.saldo = s.saldo - t.nominal where t.jenis = '$jenis' and s.id = 't.$uid'";
$sql3= "update saldo s INNER JOIN transaksi t ON s.id = t.uid set s.saldo = s.saldo + t.nominal where t.jenis = '$jenis and s.id = 't.$uid'";
if ($nominal=='' || $jenis==''|| $tanggal==''){
echo '<script language="javascript">';
echo 'alert("Masukan Inputan !!")';
echo '</script>';
}
else{
if(mysqli_query($conn,$sql) && mysqli_query($conn,$sql2) && mysqli_query($conn,$sql3)){
//var_dump(mysqli_query($conn,$sql2));
echo '<div class="alert alert-success" role="alert"> Sukses Add Data !!! </div>';
header("Refresh: 1; url=index.php");
//echo '<script> location.replace("index.php")</script>';
}
else {
echo "Error !" . $conn->error;
}
}
this code to edit data and update the balance to table balance. i dont know the wrong this code
if(isset($_POST['submit'])){
$edit = $_GET['edit'];
$uid = $_POST['uid'];
$nominal = $_POST['nominal'];
$jenis = $_POST['jenis'];
$tanggal = $_POST['tanggal'];
$update = "update transaksi set uid= '$uid', nominal= '$nominal',jenis= '$jenis',tanggal='$tanggal' where id = '$edit'";
$sql2= "update saldo s INNER JOIN transaksi t ON s.id = t.uid set s.saldo = s.saldo - t.nominal where t.jenis = '$jenis' and uid = '$uid'";
$sql3= "update saldo s INNER JOIN transaksi t ON s.id = t.uid set s.saldo = s.saldo + t.nominal where t.jenis = '$jenis and uid = '$uid'";
if(mysqli_query($conn, $update) && mysqli_query($conn,$sql2) && mysqli_query($conn,$sql3)){
// echo $edit;
echo '<div class="alert alert-success" role="alert"> Sukses Edit Data !!! </div>';
header("Refresh: 1; url=index.php");
//echo '<script> location.replace("index.php")</script>';
}
else{
echo "Gagal Edit Data !" . $conn->error;
}
}
this picture table database