insert and update current amount with the new amount

0

I would like your opinions on what is the most advisable thing to do in this case: first I have a table of values that is where the amounts are recorded in newspapers.

trasvalores:
Id_trasvalores
monto_trasvalores_apertura
Amount_Transfer_current | date
hour
id_usuarios
delivered received place_origin

denominations:
id_denomination
denomination
quantity
amount
id_trasvalores

Registration process

<!-- proceso para registrar-->

<?php
 if(isset($_POST['guardar'])){


 $sql = "SELECT fecha FROM trasvalores WHERE fecha = :fecha LIMIT 1"; 
 //Creamos la select
 $check = $DB_con->prepare($sql); //Preparamos la SELECT, de ésta manera evitamos SQL Injection
 $check->bindParam(':fecha', $_POST['fecha']);//Substituimos las variables de la SELECT
 $check->execute();//Ejecutamos la consulta
 $contador = $check -> rowCount();//Esta función devuelve el número de resultados que ha devuelto la SELECT
 if ($contador > 0) {
 $check->closeCursor();

          $errMSG = "¡ Ups Aviso: El Registro ya se Encuentra Insertado !";

 }
  else
 {


  $sql=$DB_con->prepare("INSERT INTO trasvalores (monto_trasvalores_apertura,monto_trasvalores_actual,fecha,id_usuarios,entregado,recibido,lugar_origen) VALUES ( :monto_trasvalores_apertura,:monto_trasvalores_apertura,:fecha,:id_usuarios,:entregado,:recibido,:lugar_origen)");
  $sql->bindParam(':monto_trasvalores_apertura', 
  $_POST['monto_trasvalores_apertura']);
  $sql->bindParam(':monto_trasvalores_actual', 
  $_POST['monto_trasvalores_apertura']);
  $sql->bindParam(':fecha', $_POST['fecha']);
  $sql->bindParam(':id_usuarios', $_POST['id_usuarios']);
  $sql->bindParam(':entregado', $_POST['entregado']);
  $sql->bindParam(':recibido', $_POST['recibido']);
  $sql->bindParam(':lugar_origen', $_POST['lugar_origen']);
  $sql->execute();
  $last_id = $DB_con->lastInsertId();

  for ($i = 0; $i < count($_POST['denominacion']); $i++) {

      for ($i = 0; $i < count($_POST['cantidad']); $i++) {

          for ($i = 0; $i < count($_POST['monto']); $i++) {

    $sql2=$DB_con->prepare("INSERT INTO denominaciones (id_trasvalores, denominacion,cantidad,monto) VALUES (:id_trasvalores,:denominacion, :cantidad, :monto)");
  $sql2->bindParam(':id_trasvalores', $last_id);
  $sql2->bindParam(':denominacion', $_POST['denominacion'][$i]);
  $sql2->bindParam(':cantidad', $_POST['cantidad'][$i]);
  $sql2->bindParam(':monto', $_POST['monto'][$i]);

    $sql2->execute();

          $successMSG ="¡ Bien Hecho: Registro Insertado Correctamente !";


                      } 

                   } 
              } 
          }
      }
   ?>
   <!-- fin proceso para registrar-->

Now what is the problem that if I have an open amount of x value example I have an open amount of 10000 and I want to make another insert the field amount_attacks_aperture and amount_total_currencies should be updated with the amount that will be recorded again example I have 10000 left and I will do a new record for 30000 in total should now be available with the new insert 40000 available.

    
asked by yoclens 26.07.2017 в 01:50
source

0 answers