I have this csv file with ; separated fields. I want to be able to read the file and put the values into session variables to insert them into a mySQL database.
I have this code for reading de file and create the array. And now I want to create the session variables to pass them to the insert.php file.
Content of my csv file:
“S11PBMS02.14045″;16.93;5;NULL;NULL;1;NULL;217.64;1;NULL;NULL;1;NULL;1;”52X45-CAR10/1XCAR10/1″;0;0;0;”140″;”PB Mini Stripe 02″;46;#;”S11PBMS02.14045″;”PB Mini Stripe 02″;”Vichy Estofos”;”PBMS02″;”140″;”52X45-CAR10/1XCAR10/1″;”090″;217.64;330.63;233.73;330.63;”C147″;”02(Fawn)”;41012;41144;;;;;;;;;;;;;;;”*”;41012;;;;;;;
My code:
<?php
$arrCSV = array();
if (($handle = fopen("style.dai", "r")) !==FALSE) {
$key = 0;
while (($data = fgetcsv($handle, 0, ";")) !==FALSE) {
$c = count($data);
for ($x=0;$x<$c;$x++) {
$arrCSV[$key][$x] = $data[$x];
}
$key++;
}
fclose($handle);
}
echo "<pre>";
echo print_r($arrCSV);
echo "</pre>";
?>
Its pretty much the same:
You could also just set the session value to be the same as $arrCSV