Hi,
I'm using code below that I found somewhere for inserting data from csv & txt files. Works fine.
The problem is that I have to insert also clientID (coming from Session) and current Date - these two last columns are empty in csv/txt files
Any help would be appreciated.
<?
$dbH = mysql_connect('localhost', 'root', '') or die('Could not connect to MySQL server.<br>' . mysql_error());
mysql_select_db('eprc') or die('Could not select database.<br>' . mysql_error());
$fcontents = file ('data4.txt');
# expects the csv file to be in the same dir as this script
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
$sql = "insert into parts_copy values ('".
implode("','", $arr) ."')";
mysql_query($sql);
//echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
mysql_close($dbH);
?>
Thank you
I'm using code below that I found somewhere for inserting data from csv & txt files. Works fine.
The problem is that I have to insert also clientID (coming from Session) and current Date - these two last columns are empty in csv/txt files
Any help would be appreciated.
<?
$dbH = mysql_connect('localhost', 'root', '') or die('Could not connect to MySQL server.<br>' . mysql_error());
mysql_select_db('eprc') or die('Could not select database.<br>' . mysql_error());
$fcontents = file ('data4.txt');
# expects the csv file to be in the same dir as this script
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
$sql = "insert into parts_copy values ('".
implode("','", $arr) ."')";
mysql_query($sql);
//echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
mysql_close($dbH);
?>
Thank you