Egad,
I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile.
But, I've been trying to find syntax to insert values into a mysql database table. I'm able to use the below syntax to insert hard-coded values like 'josie' and 'smith' but can't find working syntax to insert $scalar data from another file (which is really what perl-mysql is good for anyway... or so i thought).
Can anyone tell me why the below line of code won't insert data from the non-mysql file ("mailGroupsADP List.csv") ... into the mysql db?
$ADP_data_to_in sert = "INSERT INTO Employee(FirstN ame,LastName) VALUES($FIRST,$ LAST)";
--
I get 200 variations of the following error:
"Use of uninitialized value in concatenation (.) or string at comma_to_tab_to _db4
.pl line 22, <CSV> line 102.
DBD::mysql::st execute failed: You have an error in your SQL syntax near ')' at
line 1 at C:/Perl/site/lib/MySQL.pm line 175, <CSV> line 102."
-----------
ps: i can't even get INSERT INTO to insert scalars from a simple text file.
------------
partially redacted body of code below:
I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile.
But, I've been trying to find syntax to insert values into a mysql database table. I'm able to use the below syntax to insert hard-coded values like 'josie' and 'smith' but can't find working syntax to insert $scalar data from another file (which is really what perl-mysql is good for anyway... or so i thought).
Can anyone tell me why the below line of code won't insert data from the non-mysql file ("mailGroupsADP List.csv") ... into the mysql db?
$ADP_data_to_in sert = "INSERT INTO Employee(FirstN ame,LastName) VALUES($FIRST,$ LAST)";
--
I get 200 variations of the following error:
"Use of uninitialized value in concatenation (.) or string at comma_to_tab_to _db4
.pl line 22, <CSV> line 102.
DBD::mysql::st execute failed: You have an error in your SQL syntax near ')' at
line 1 at C:/Perl/site/lib/MySQL.pm line 175, <CSV> line 102."
-----------
ps: i can't even get INSERT INTO to insert scalars from a simple text file.
------------
partially redacted body of code below:
Code:
$EmployeeData = Mysql->connect($host, $db, $user, $password);
$EmployeeData->selectdb('Copy_of_Employee');
$tablename = "Employee";
$file = 'f:\\webaddress\\EmailGroupsADPList.csv';
$csv = Text::CSV->new();
$FIRST = $file[1];
$LAST = $file[0];
open (CSV, "<", $file);
while (<CSV>) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
$ADP_data_to_insert = "INSERT INTO Employee(FirstName,LastName) VALUES($FIRST,$LAST)";
$query = $EmployeeData->query($ADP_data_to_insert);
} else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close CSV;
Comment