How to Insert Values in Database Table in Magento

user769394 picture user769394 · Oct 11, 2011 · Viewed 16.6k times · Source

I have created an Admin (Backend) module in Magento where i have created few text fields .. I have created the respective Model for that as well.. When i press my save button it posts the data and I can print_r the value in my Controller. Now I want to store this data into my table.. How can I do it... ?

I am writing the code something like this (Controller):-

public function postAction()
{

        $postData = $this->getRequest()->getPost();
        //print_r($postData);exit;
        $model = Mage::getModel('cod/cod');
        //print_r($model);exit;
        $model->setCodId($this->getRequest()->getParam('cod_id'))
            ->setAmount($postData['amount'])
            ->setStatus($postData['status'])
            ->save();
        Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Rule was successfully saved'));

        $this->_redirect('*/*/index');'
}

Can Anyone help me with this and I would Like to know what i need to write in my model file..

Answer