Marrr
Marrr

Reputation: 15

An uncaught Exception was encountered - ParseError

So I encountered a Parse Error while trying to do the code below with a message saying: syntax error, unexpected ';', expecting ')'

<?php
class csv_model extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }
    function uploadData()
    {
        $count=0;
        $fp = fopen($_FILES['userfile']['tmp_name'],'r') or die("can't open file");
        while($csv_line = fgetcsv($fp,1024))
        {
            $count++;
            if($count == 1)
            {
                continue;
            }
            for($i = 0, $j = count($csv_line); $i < $j; $i++)
            {
                $insert_csv = array();
                $insert_csv['id'] = $csv_line[0];
                $insert_csv['empName'] = $csv_line[1];
                $insert_csv['empAddress'] = $csv_line[2];

            }
            $i++;
            $data = array(
                'id' => $insert_csv['id'] ,
                'empName' => $insert_csv['empName'],
                'empAddress' => $insert_csv['empAddress'],
            $data['crane_features']=$this->db->insert('useraccount', $data);
        }
        fclose($fp) or die("can't close file");
        $data['success']="success";
        return $data;
    }
}

The Line where the error was showing was at this one

$data['crane_features']=$this->db->insert('useraccount', $data);

I don't think that there is anything wrong with my code but then again, I might be wrong because I just recently learned CI.

Upvotes: 0

Views: 633

Answers (1)

Devsi Odedra
Devsi Odedra

Reputation: 5322

You forgot to close array here after 'empAddress' => $insert_csv['empAddress']

$data = array(
                'id' => $insert_csv['id'] ,
                'empName' => $insert_csv['empName'],
                'empAddress' => $insert_csv['empAddress']);

Upvotes: 1

Related Questions