Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Jordan Czarnik
Jordan Czarnik
1,478 Points

Why am I getting an Undefined Index

I am modifying an opencart module and I cant get the module to pull the php variable

My Model Code is:

public function addTransaction($customer_id, $description = '',  $amount = '', $N2Ugiven = '', $N2Ufrom = '', $order_id = 0) {
    $customer_info = $this->getCustomer($customer_id);

    if ($customer_info) {
        $this->db->query("INSERT INTO " . DB_PREFIX . "customer_transaction SET customer_id = '" . (int)$customer_id . "', order_id = '" . (int)$order_id . "', description = '" . $this->db->escape($description) . "', amount = '" . (float)$amount . "', N2Ugiven = '" . $this->db->escape($N2Ugiven) . "',  N2Ufrom = '" . $this->db->escape($N2Ufrom) . "', date_added = NOW()");

My Controller Code Is:

    if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/customer')) {
        $this->model_sale_customer->addTransaction($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['N2Ufrom'], $this->request->post['N2Ugiven'], $this->request->post['amount']);

        $data['success'] = $this->language->get('text_success');
    } else {
        $data['success'] = '';
    }

    if (($this->request->server['REQUEST_METHOD'] == 'POST') && !$this->user->hasPermission('modify', 'sale/customer')) {
        $data['error_warning'] = $this->language->get('error_permission');
    } else {
        $data['error_warning'] = '';
    }

    $data['text_no_results'] = $this->language->get('text_no_results');
    $data['text_balance'] = $this->language->get('text_balance');

    $data['column_date_added'] = $this->language->get('column_date_added');
    $data['column_N2Ugiven'] = $this->language->get('column_N2Ugiven');
    $data['column_N2Ufrom'] = $this->language->get('column_N2Ufrom');
    $data['column_description'] = $this->language->get('column_description');
    $data['column_amount'] = $this->language->get('column_amount');

    if (isset($this->request->get['page'])) {
        $page = $this->request->get['page'];
    } else {
        $page = 1;
    }

    $data['transactions'] = array();

    $results = $this->model_sale_customer->getTransactions($this->request->get['customer_id'], ($page - 1) * 10, 10);

    foreach ($results as $result) {
        $data['transactions'][] = array(
            'amount'      => $this->currency->format($result['amount'], $this->config->get('config_currency')),
            'N2Ugiven'    => $result['N2Ugiven'],
            'N2Ufrom'     => $result['N2Ufrom'],
            'description' => $result['description'],
            'date_added'  => date($this->language->get('date_format_short'), strtotime($result['date_added']))
        );  
    }

when i go to add the transaction i get an Notice: Undefined index: N2Ugiven in controller.

If i remove the post data from controller it works but does not post N2Ugiven and N2Ufrom