php - Insert Data Using Custom View In Opencart -


when user submit data getting error

fatal error: uncaught error: call member function insert() on null in c:\xampp\htdocs\smac\catalog\controller\payment\payment.php:45

this tpl file

<script type="text/javascript">     $('#submit').submit(function() {     $.ajax({ // create ajax call...         data: $(this).serialize(),          type: $(this).attr('method'),         url: $(this).attr('action'),          success: function(response) {              $('#submit').html(response);          }     });     return false;  }); </script>     <form action="<?php echo $action; ?>" method="post">     name: <input type="text" name="name" required><br>     e-mail: <input type="text" name="email" required><br>     <input type="submit" value="submit" name="submit">     </form 

controller file:

public function index()      {      $this->load->model('payment/payment');     $this->data['action'] = $this->url->link('payment/payment');  if (($this->request->server['request_method'] == 'post')) {      $id= $this->model_payment_payment->insert($this->request->post);         }          $this->response->setoutput($this->load->view('payment/payment', $data));         } 

this model file

<?php   class modelpaymentpayment extends model  {       public function insert($data)      {          $this->db->query("insert " . db_prefix . "naveen set                  name = '" . $this->db->escape($data['name']) . "',                  email = '" . $this->db->escape($data['email']) . "'");      $address_id = $this->db->getlastid();         return $address_id;     } } 

if have mistaken please mentioned it.

i think problem in controller file. should use either

$this->data['action'] = $this->url->link('payment/payment'); $this->response->setoutput($this->load->view('payment/payment', $this->data)) 

or

$data['action'] = $this->url->link('payment/payment'); $this->response->setoutput($this->load->view('payment/payment', $data)) 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -