0

I'm using PHP Excel to insert data CSV into database. But i confused to apply it.

Here's Mycode:

<?php 
session_start();
include 'connect.php';
include 'PHPExcel/Classes/PHPExcel/IOFactory.php';
$input=$_POST['times'];
$rev=$_POST['rev'];
$chan=$_POST['channel'];
$uploadid='UP'.$_POST['number'];
$fcid = 'FC'.$_POST['number'];
$schid = 'SCH'.$_POST['number'];
$file = $_POST['filename'];
$inputFileName = 'D:/ForecastCapacity/'.$file;
echo($input.'/'.$rev.'/'.$chan.'/'.$uploadid.'/'.$file);
//  Read your Excel workbook
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
//  Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0); 
$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestDataColumn();
// $cekk = pg_query("SELECT COUNT (inputtime) From FC WHERE InputTime = '$input'");
// $row = pg_fetch_array($cekk);
// $total = $row[0];
for ($row = 1; $row <= $highestRow; $row++){ 
    //  Read a row of data into an array
    $rowDatabln = $sheet->rangeToArray('A' . $row . ':' . 'A' . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
        $rowDatatgl = $sheet->rangeToArray('B' . $row . ':' . 'B' . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
         $rowDatajam = $sheet->rangeToArray('C' . $row . ':' . 'C' . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
         $rowDatafc = $sheet->rangeToArray('D' . $row . ':' . 'D' . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
    $eva = pg_query("INSERT INTO FC VALUES('$fcid','$schid','$uploadid','$input','$chan','$rowDatabln[$row]','$rowDatatgl[$row]','$rowDatajam[$row]','$rowDatafc[$row]',NULL,'ForecastCapacity');");

    //  Insert row data array into your database of choice here
}

?>

But when i tried to insert variable as array of variable, it doesn't work.

The Error :

Parse error: syntax error, unexpected ']', expecting identifier
(T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in 
C:\xampp\htdocs\SchedulingApplication\Code\dosavecapacity.php on line 47

How am i supposed to do?

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
Shieryn
  • 234
  • 2
  • 15
  • 1
    I'd strongly recommend learning a bit about SQL queries (and quoted strings in SQL), so that you could change this to a prepared statement with bind variables; and about PHP strings with single/double quotes - http://us2.php.net/manual/en/function.pg-prepare.php – Mark Baker May 25 '16 at 09:36
  • @MarkBaker Thanks. Could you tell me how the variable $rowDatabln can be echo? – Shieryn May 25 '16 at 10:14

0 Answers0