Decimals when editing record with modal

1

Good morning when doing the edition of a record that is the total of the invoice I get the price as well; 1,500.00 € which is as I want, but when editing the record as I get 1,500.00, if I do not edit it becomes 1.00 € and if I edit it but leaving the "." also happens the same, oslo works if I delete the field and put again 15000. This field in SQL I have it as decimal(10,2) and then in the query to make it look good I do so:

  SELECT DATE_FORMAT((pedidos.Fecha),'%d/%m/%Y') Fecha, 
    pedidos.id AS pedID, DATE_FORMAT((pedidos.Vencimiento),'%d/%m/%Y') 
    Vencimiento, pedidos.Producto AS idPr, pedidos.Tipo, 
  FORMAT(pedidos.Total, 2) Total, pedidos.Estado, productos.id, 
    productos.producto, productos.alias, Usuarios.IdUsuario AS idUs, 
    Usuarios.Nombre 
  FROM pedidos, productos, Usuarios WHERE 
    pedidos.Producto = productos.id AND pedidos.Iduser = 
    Usuarios.IdUsuario");

If you notice the fomateo with this FORMAT(pedidos.Total, 2) Total,

In the record edition it looks like this:

<?php
 $id = $_POST['eIdp'];
 $cliente = $_POST['eIDCliente'];
 $producto = $_POST['select2-2'];
 $eFecha = $_POST['eFecha'];
 $eVencimiento = $_POST['eVencimiento'];
 $estado = $_POST['select2-1'];
 $tipo = $_POST['select2-4'];
 $total = $_POST['eTotal'];

 $resultes = "Update pedidos Set Fecha='$eFecha', 
              Vencimiento='$eVencimiento', Estado='$estado', 
              Producto='$producto', Tipo='$tipo', Total='$total' 
              where id= $id";


 if ( !mysqli_multi_query($mysqli, $resultes)) {
      die( 'Error: ' . mysqli_error() );
 }

 mysqli_close($mysqli);
 ?>
    
asked by Miguel 19.09.2018 в 07:32
source

1 answer

1

The problem is that the field of the database is a numeric data and you should treat it as such, you should not send it neither commas nor currency symbols.

. . .
$tipo = $_POST['select2-4'];
$total_wf = $_POST['eTotal'];
$total = preg_replace('/[^0-9.]/s', '', $total_wf); // Se elimina la coma y algun otro caracter.

$resultes = "Update pedidos Set ..." // El query
. . .
    
answered by 19.09.2018 / 08:55
source