I have the following table
CREATE TABLE IF NOT EXISTS `payment_data` (
`orderid` int(11) NOT NULL,
`orderDesc` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`orderAmount` float NOT NULL,
UNIQUE KEY `orderid` (`orderid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
and I'm trying to insert a line in it using PHP.
$sql = 'INSERT INTO payment_data '.
'(orderid, orderDesc, name, email, orderAmount) '.
'VALUES ( '.$form_order_id.', "'.$form_order_desc.'", "'.$form_name.'", "'.$form_email.'", '.number_format($form_order_amount, 2, '.', ',').' )';
The problem is that "orderAmount" is inserted without the decimal part. For example if $form_order_amount=30,45 then 30 is what's inserted in database.
I used number_format() because it's supposed to convert "30,45" to "30.45".
orderAmountfloat(7,2)` or something desireable30,45with a,decimal is not a valid number to a computer; you need a decimal point (.) when inserting to MySQLfloatfor database money, use decimal.... or even better, adjust the value to cents so you're working with integers if you ever need to do adjustments for tax calculations, etc where floating point precision may cause issues30,45to30.45, but will do the reverse