i found a coding here that can read csv and display the list of data.my problem is it didnt insert the data into mysql.it dont have problem display the data however.
why it didnt insert into mysql?
<?php
Connect to a local database server (or die)
$dbH = mysql_connect('localhost', '', '') or die('Could not connect to MySQL server.<br>' . mysql_error());
Select the database to insert to
mysql_select_db('apple_sql') or die('Could not select database.<br>' . mysql_error());
$file_name= $_FILES['csvfile']['name'];
$columnheadings = 0; ##columnheadings,whether there is field name in csv file##
$pass = 0;
$fail = 0;
$row = 1;
$handle = fopen ("$file_name","r");
while ($data = fgetcsv ($handle, 1000, ",")) {
$num = count ($data);
echo "<p> $num fields in line $row: <br>\n";
$row++;
for ($c=$columnheadings; $c < $num; $c++) {
echo $data[$c];
$insertrecord = "Insert Into details Values ($data[$c])";
mysql_query($insertrecord);
if(mysql_error()) {
$fail += 1; # increments if there was an error importing the record
}
else
{
$pass += 1; # increments if the record was successfully imported
}
}
}
echo "fail" .$fail."</br>";
echo "pass" . $pass;
fclose ($handle);
?>