Hi all,
I'm trying to import an Excel file with three columns into a Mysql table but without success: The column are isin, data and dividendo that are text, date and double formatted
The code is:
$db_host = "localhost";
$db_user = "user";
$db_password = "pwd";
$db_name = "db_name";
$pntDB = mysql_connect($db_host, $db_user, $db_password);
if ($pntDB == FALSE) die ("Errore nella connessione.");
mysql_select_db($db_name, $pntDB) or die ("Errore nella selezione del database.");
if(isset($_POST['submit'])) {
$filename=$_POST['filename'];
if (($handle = fopen("$filename", "r"))!== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$array = explode("/", $data[1]);
// Riorganizzo gli elementi in stile YYYY/MM/DD
$data_mysql = $array[2].'-'.$array[0].'-'.$array[1].' 00:00:00';
echo "$data[0],$data_mysql,$data[2]<br>";
// aggiorno la tabella dividendi
$sql = "INSERT INTO dividendi (isin,data,dividendo) VALUES('$data[0]','$data_mysql',$data[2])";
// lancio la query
$result = mysql_query($sql, $pntDB);
// controllo l'esito
if (!$result) {
die("Errore nella query $query: " . mysql_error());
}
}
fclose($handle);
echo "Import done.'<br>'";
}
} else { ?>
<center>
<table>
<form action='importExcel.php' method='post'><br>
<tr><td align=center>Type .csv file name to import:<br><br></td></tr>
<tr><td><input type='text' name='filename' value='c:\simo\home\etfconsulting\update_etfplus.net\dividendi2006euro.csv' size='100'>
<br><br></td></tr>
<tr><td align=center><input type='submit' name='submit' value='submit'></td></tr>
</form>
</table>
</center>
<? } ?>
The problem is that i'm not able to insert these values in mysql table... do you know why ??