because when I change an integer value to a decimal I get an error?

0

good morning

Working with php, I'm making a shopping cart. everything was fine until I realized that it does not save me values with decimals, pure integers in tables such as prices or totals, etc.

my tables had them in decimal type, then I changed them to double and I did not affect anything. Only when the data has decimals sends me this error:

total Compra1 :16073 total desc 1607,3 total Compra:14465,7 error al insertar datos de compra Column count doesn't match value count at row 1

I printed the values that I have to see the accounts. in that example if I do not remove the discount, save it without errors

this is my table

and this is the insert code

echo '<br>total Compra1 :'.$totalCompra.'<br>';
$totalDescuento=$totalCompra*($descuentoStatus/100);
echo 'total desc '.$totalDescuento;
$totalCompra= $totalCompra-$totalDescuento;
   echo '<br>total Compra:'.$totalCompra.'<br>';
   //$totalCompra=$totalCompra+$gastosEnvio;
 mysqli_query( $conexion, "INSERT INTO compras (numeroCompra, idDistr, nomDistr, fechaCompra, formaPago, articulos, totalCompra, descuento, statusCompra) VALUES ('$numeroCompra','$IDUSUARIO','$nomUsuario', '	$fecha', '$formaPago', '$articulosTotal', $totalCompra, '$descuentoStatus', '$statusCompra')" )or die( "error al insertar datos de compra " . mysqli_error( $conexion ) ); 

To insert it well. I added this code to format with the . point, but how can I do it so that the format is applied to all the pages. Or I do variable by variable

   number_format($número, 2, '.', '');

// 1234.56

    
asked by EngelDragoner 21.08.2018 в 20:26
source

1 answer

1

The only thing I see differently is that the field totalCompra is without quotes, so something like 11.2 must arrive and the query interpret that , believes that they are two different parameters, therefore put them between comllias or make sure the data arrives with . so that it is well received, try this way:

mysqli_query( $conexion, "INSERT INTO compras 
(numeroCompra, idDistr, nomDistr, fechaCompra, formaPago, articulos, totalCompra, descuento, statusCompra) 
VALUES 
('$numeroCompra','$IDUSUARIO','$nomUsuario', '$fecha', '$formaPago', '$articulosTotal', '$totalCompra', '$descuentoStatus', '$statusCompra')" 
)or die( "error al insertar datos de compra " . mysqli_error( $conexion ) );

I hope you serve, you tell me how it went!

    
answered by 21.08.2018 в 21:05