Okay, I'm having some serious issues here. I'm new to this site, and new to dealing with importing CSV data via PHP, and also I'm newbies in programming.
when i importing csv file into mysql there is some added data on my database filed here is my script to upload csf file into mysql
<?php
include '../php/koneksi.php';
if(isset($_POST["Import"])){
$filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
while (($Data = fgetcsv($file, 1000, ",")) !== FALSE)
{
//It wiil insert a row to our subject table from our csv file`
$sql = "INSERT into raport (`no_induk`, `nama`, `kelas`, `jurusan`,mapel, `semester`, `nilai`, `deskripsi`)
values(
'".trim($Data[0], '"')."',
'".trim($Data[1], '"')."',
'".trim($Data[2], '"')."',
'".trim($Data[3], '"')."',
'".trim($Data[4], '"')."',
'".trim($Data[5], '"')."',
'".trim($Data[6], '"')."',
'".trim($Data[7], '"')."'
)";
//we are using mysql_query function. it returns a resource on true else False on error
$result = mysql_query( $sql);
if(! $result )
{
echo "<script type=\"text/javascript\">
alert(\"Invalid File:Please Upload CSV File.\");
window.location = \"upload.php\"
</script>";
}
}
fclose($file);
//throws a message if data successfully imported to mysql database from excel file
echo "<script type=\"text/javascript\">
alert(\"CSV File has been successfully Imported.\");
window.location = \"upload.php\"
</script>";
//close of connection
mysql_close;
}
}
?>