0

I'm using the Zend_db_table insert() method and get an error. The error is because I receiving data from POST as a string but the datatype for the table column is float. So it creates error when I try to insert string type into float column.

What's the proper way to resolve this?

Here's the model code:

class User_Model_Forms extends Zend_Db_Table_Abstract {
    public function save(array $data) {
        return $this->insert($data);
    }
    ...

Here's the controller code:

$form = new User_Form_Firstpart();
if ( $form->isValid($request->getPost()) ){
    $data = $form->getValues();
    $formModel = new User_Model_Forms();
    $formModel->save($data);

    ...

Here's the database table:

form table

Owen
  • 7,347
  • 12
  • 54
  • 73

1 Answers1

1

Try converting the input to float before passing it to insert:

$this->insert(array(
    'someColumn' => (float) $the_value,
));

BTW don't forget to add a float validator to your form.

Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194