I am trying to upload a csv file and save it in db. The problem is its returning Notice Error
Notice: Use of undefined constant csv - assumed 'csv' in D:\xampp\htdocs\nag\admin\process\upload_case.php on line 5
Notice: Use of undefined constant size - assumed 'size' in D:\xampp\htdocs\nag\admin\process\upload_case.php on line 5
Notice: Undefined index: csv in D:\xampp\htdocs\nag\admin\process\upload_case.php on line 5
I have stuck with it since 2 hours debugging, can some one please help fix.
Below is the code.
<?php
include "../config/config.php";
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
mysql_query("INSERT INTO case_view (
courtname, casenumber, year, pfname, plname,
cell, fhearing, cstatus, cdescri
) VALUES (
'" . addslashes($data[0]) . "',
'" . addslashes($data[1]) . "',
'" . addslashes($data[2]) . "',
'" . addslashes($data[3]) . "',
'" . addslashes($data[4]) . "',
'" . addslashes($data[5]) . "',
'" . addslashes($data[6]) . "',
'" . addslashes($data[7]) . "',
'" . addslashes($data[8]) . "'
)
");
}
} while ($data = fgetcsv($handle, 1000, ",", "'"));
//
//redirect
header('Location: import.php?success=1'); die;
// echo "Import Successfull";
}
?>
PDOwithprepared statementsfor performance reasons.