hi,
i want to make a program where the csv file directly insert into the mysql database table.
i found the code:
<?php
include 'mysql-connect.php';
$rec=0;
$handle = fopen ('datafile1.csv', 'r');
while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE)
{
$rec++;
if($rec==1)
{
continue;
}
else
{
$query = "INSERT INTO Book_details VALUES ('". implode("','", $data)."')";
$query = @mysql_query($query);
}
}
?>
it working fine .
but i have to face problem when i specify the columns in the mysql table like
while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE)
{
$query = "INSERT INTO Book_details(idt_no,book_name,author_name,publisher_name,condition,condition_note,price,cur,quantity) VALUES ('". implode("','", $data)."')";
$query = @mysql_query($query);
}
no value is insert in the data base???
mention that database have 12 columns and csv have 9.
i have to insert all 9 to selected 9 columns in the database.
plz help me....