Forum Moderators: coopster
$data = mysql_query("LOAD DATA LOCAL INFILE 'C:\\\Program Files\\\write whole path to your cvs file(dont remove the three slashes)\\\your_cvs_filename.CSV'
INTO TABLE zzz.tablename
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(a,b,c,d,e)") These are your actual fields name in the table
or die(mysql_error());
?>
Am gonna use this import module in an application, i used fopen, the problem is, i am able upload the csv file from same directory but am unable to upload from any other directory
here the code..
<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("test",$con);
//$result = mysql_query($query);
$csv=$_GET['file1'];
echo "the csv is".$csv;
$row = 1;
$handle = fopen($csv,"r");
$field='';
$rowcount=0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
if($row==1)
{
for ($c=0; $c < $num; $c++)
{
$field = $field . $data[$c] ." "."VARCHAR(50)";
if($c==$num-1)
{
$field=$field;
}
else
{
$field=$field.",";
}
}
//echo "the val".$field;
$row++;
}
else
{
for ($c=0; $c < $num; $c++)
{
//echo "data".$data[$c] . "<br />\n";
$values=$values . "'".$data[$c]."'";
if($c==$num-1)
{
$values=$values;
}
else
{
$values=$values.",";
}
if($row == 14)
{
$totval = $totval . "(".$values.")";
}
else
{
$totval = $totval . "(".$values.")".",";
echo $totalval;
}
$values='';
$row++;
}
}
echo "The total value is".$totalval;
//echo $totval;
fclose($handle);
if(preg_match("/-/",$csv))
{
//echo "this name has hypon";
$tab1=explode("-",$csv);
$tablename=$tab1[0];
}
else
{
$tab1=explode(".",$csv);
$tablename=$tab1[0];
}
$cat="create table $tablename($field)";
mysql_query($cat);
if(mysql_error()){ echo mysql_error()."<br>"; }
$sql = "insert into $tablename values $totval";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error())
{
echo "this".mysql_error() ."<br>\n";
}
else
{
echo"<h3>You have successfuly updated the whatever ..?<br>
}
?>
please correct my code...
thanks in advance
Warning: fgets(): supplied argument is not a valid stream resource in C:\xampp\htdocs\CEOTOOLs\test\landing.php on line 21
Warning: fclose(): supplied argument is not a valid stream resource in C:\xampp\htdocs\CEOTOOLs\test\landing.php on line 25
Warning: fopen(report.csv) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\CEOTOOLs\test\landing.php on line 26
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\CEOTOOLs\test\landing.php on line 27
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\CEOTOOLs\test\landing.php on line 27
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\CEOTOOLs\test\landing.php on line 27
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\CEOTOOLs\test\landing.php on line 27
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\CEOTOOLs\test\landing.php on line 27
i got this
$csv = '/path/to/file.php';