Greetings all,
I have a small php program below (my first) that attempts to take a comma quote text file and load it into a MYSQL table. When I compile the program I get the following error:
Parse error: parse error, unexpected T_STRING in ... on line 57 which is the open file line
Any ideas and/or suggestions? thanks very much in advance
<?php
require_once 'DB.php';
include 'Smarty/libs/Smarty.class.php';
// Hard coded values ...
//testing
$idcardload = "/hdir/work/php/HOLD/M38.ID.CARD.LOAD.txt";
// Put this stuff into a include file
$user = 'user1';
$pass = 'testpass';
$host = 'localhost';
$db_name = 'idcard_info';
//Data Source name
$dsn = "mysql://$user:$pass@$host/$db_name";
function insertidcardData($dataArray, $connection) {
// Perform SQL statement for replacing courses.
// $sql = "REPLACE INTO idcard_info ( id, firstname, middlename, lastname, nickname, birthdate,staffflag,
// studentflag, barcodestu, barcodestaff, mealplanfall, mealplanwinter,
// mealplancanceldatefall, mealplancanceldatewinter, photolocationstu,
// photolocationstaff, residencefall, residencewinter)
// VALUES ('$dataArray[1]','$dataArray[2]','$dataArray[3]','$dataArray[4]','$dataArray[5]','$dataArray[6]','$dataArray[7]','
// '$dataArray[8]','$dataArray[9]','$dataArray[10]','$dataArray[11]','$dataArray[12]','
// '$dataArray[13]','$dataArray[14]','$dataArray[15]','
// '$dataArray[16]','$dataArray[17]','$dataArray[18]',');
$sql = "REPLACE INTO idcard_info ( id, firstname, middlename, lastname, nickname, birthdate,staffflag,
studentflag, barcodestu, barcodestaff, mealplanfall, mealplanwinter,
mealplancanceldatefall, mealplancanceldatewinter, photolocationstu,
photolocationstaff, residencefall, residencewinter)
VALUES ('$dataArray[1]','$dataArray[2]','$dataArray[3]','$dataArray[4]','$dataArray[5]','$dataArray[6]','$dataArray[7]','
'$dataArray[8]','$dataArray[9]','$dataArray[10]','$dataArray[11]','$dataArray[12]','
'$dataArray[13]','$dataArray[14]','$dataArray[15]','
'$dataArray[16]','$dataArray[17]','$dataArray[18]',');
print $sql;
$result = $connection->query($sql);
if (DB::isError($result)) {
print $db->getMessage());
exit;
}
}
}
}
// ************* MAIN *********** //
// Open extract file
$fp = fopen($idcardload,"r");
// Connect to database
$db = DB::connect($dsn);
if (DB::isError($db)) {
print $db->getMessage());
exit;
}
while ($data = fgetcsv ($fp, 1000, ",")) {
$num = count ($data);
insertidcardData($data, $db);
}
$db->disconnect();
fclose($fp);
?>