Hi,
Got this script, but now when the data is in the table (id)
nothing happens, I would like the record to be updated with the new values from csv file.
Anyone can help me write this ?
This is what I have:
Got this script, but now when the data is in the table (id)
nothing happens, I would like the record to be updated with the new values from csv file.
Anyone can help me write this ?
This is what I have:
Code:
mysql_select_db($database_ASN, $ASN);
$fp = fopen('UploadedMatch.csv', 'r');
// first line has column names
$data = fgetcsv($fp, 2048, ';');
$columns = array();
foreach($data as $column)
{
$columns[] = trim($column, '"');
}
$sql = 'INSERT INTO testtable (';
$sql .= implode($columns, ', ');
$sql .= ') VALUES (';
// next lines have values
while (($data = fgetcsv($fp, 2048, ';')) !== FALSE)
{
$sql2 = $sql;
foreach($data as $column)
{
$column = mysql_real_escape_string($column);
$sql2 .= "'{$column}', ";
}
$sql2 = rtrim($sql2, ', ');
$sql2 .= ')';
echo 'Executing: ' . $sql2 . '</br>';
mysql_query($sql2) or print(mysql_error() . '<br>');
}
fclose($fp);
?>