vendredi 28 mai 2021

how can i decrease my balance with PHP MySQL

so i have the parking system with PHP-MySQL project. there are 2 table, mahasiswa and dataparkirs. the mahasiswa have 1 field name 'saldo' it means the balance of user to park the vehicle. so when the vehicle is parking out the balance in table mahasiswa, which name is 'saldo' is cut by 3000 constantly.

so i had to fil the value of saldo to 8000. how can i write the formula to cut the balance in saldo is decrease by 3000 constantly?

<?php
     
    require 'database.php';


    if ( !empty($_POST)) {
        
        // keep track post values
        ini_set('date.timezone', 'Asia/Jakarta');
        $no_kartu = $_POST['no_kartu'];
        $jam_keluar = date("Y-m-d H:i:s");
        $status = 'keluar';
        $saldo = $_POST['saldo'];
        $tarif = 3000;
        $total_bayar = $saldo - $tarif;

        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        $sql = "UPDATE dataparkirs SET jam_keluar = '$jam_keluar', status = '$status' WHERE no_kartu = $no_kartu ";
        $q = $pdo->prepare($sql);
        $q->execute(array($jam_keluar,$status));

        $sql = "UPDATE mahasiswa SET saldo = '$total_bayar' WHERE no_kartu = $no_kartu ";
        $q = $pdo->prepare($sql);
        $q->execute(array($total_bayar));
        Database::disconnect();
        header("Location: parkirmasuk.php");
    }

?>



Aucun commentaire:

Enregistrer un commentaire