SQLSTATE[HY000]: General error: 1366 Incorrect decimal value: ERROR

SQLSTATE[HY000]: General error: 1366 Incorrect decimal value: ERROR

meskimeskimeskimeski Posts: 7Questions: 4Answers: 0

After updating mysql get error when creating new row
SQLSTATE[HY000]: General error: 1366 Incorrect decimal value: '' for column 'prepay' at row 1
Create

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    sounds like you are not formatting a decimal column properly for insert. if it is a decimal number it may only contain numbers and a decimal point. Everyhting else is not permitted. If you are using a different way of displaying your column in editor you need to use a set formatter on the server side. I use this logic in my setFormatter to get rid of 1,000 separators and decimal commas: English number format for 1 million and 99 cents is 1,000,000.99, German format is 1.000.000,99. This little routine converts both numbers into 1000000.99 which is what MySql understands.

    //explode to get rid of the 1,000 separators
        //works also for rates!!
        if ($_SESSION['lang'] === 'de') {     
            $numberArray = explode('.', $val);
        } else {
            $numberArray = explode(',', $val);
        }
        //implode without delimiter to join the pieces again
        $numberString = implode($numberArray);
        //replace the German decimal comma with a period
        if ($_SESSION['lang'] === 'de') {   
            $numberString = str_replace(',', '.', $numberString);
        }
    

    Here is more detail on the formatters:
    https://editor.datatables.net/manual/php/formatters#Formatter-methods
    Use a custom formatter through a closure. That gives you more flexibility.

This discussion has been closed.