1

I'm able to fetch data from custom form but not able to put it in database table.

    $model = $this->_name->create();
    $entity = $this->getRequest()->getParams();
    $model->addData([
        "entity_id" => $entity['entity_id'],
        "customer_id" => $entity['customer_id'],
        "position" => $entity['position'],
        "department" => $entity['department']
    ]);

    $saveData = $model->save();

    if($saveData)
    {
        $this->messageManager->addSuccess('Record Inserted...!');
    }
    else
   {
      $this->messageManager->addSuccess('Record Inserted...!');
   }

SimpleMagento\Custom\Model\Name.php

class Name extends \Magento\Framework\Model\AbstractModel 

{ public function _construct() { $this->_init('SimpleMagento\Custom\Model\ResourceModel\Name');
} }

SimpleMagento\Custom\Model\ResourceModel\Name.php

class Name extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb

{ public function _construct() { $this->_init("new_info","entity_id"); } }

SimpleMagento\Custom\Model\ResourceModel\Name\Collection.php

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

{ public function _construct() { $this->_init("SimpleMagento\Custom\Model\Name","SimpleMagento\Custom\Model\ResourceModel\Name"); } }

  • aside from there being no difference between the $saveData and !$saveData in your example, I'd advise you wrap $model->save(); in a try {$model->save();} catch (\Excpetion $e) {//log $e->getMessage();} and see if there is an exception thrown – Barry Dec 5 '19 at 13:35
  • can you share this complete files – Asad Ullah Dec 5 '19 at 14:49
  • Can you share Error lines – Msquare Dec 18 '19 at 3:36