I'm trying to parse a few references from a file and load them to mysql table but keep on getting this error everytim,e i run the script:

DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Njuguna, M.I., Yusuf, J. A., Akama, V.,2013,Animal husbandry in the developed w' at line 1 at manuscripts3.pl line 51, <$fh> line 1.
Uncaught exception from user code:See code below


use strict;
use warnings;
use diagnostics;
use DBI;

my $driver = "mysql";
my $database = "test";
my $user = "root";
my $password = "";
my $dbh = DBI->connect(
$user, $password,
RaiseError => 1,
PrintError => 1,
AutoCommit => 0,
) or die $DBI::errstr;

my $file = "/var/www/manuscripts.txt";

open my $fh ,"<", $file;
my @manuscripts;
while (my $lines = <$fh>){
    $lines =~ s/\, \(/\t/g;
    $lines =~ s/\) \“/\t/g;
    $lines =~ s/\” /\t/g;

my ($authors, $year, $title, $journal) = split (/\t/, $lines);

What i'm i doing wrong?

3 Years
Discussion Span
Last Post by DaveAmour

this is the textfile

Kamau, M.A., Njuguna, M.I., Yusuf, J. A., Akama, V., (2013) “Animal husbandry in the developed world” Journal of Hospital Infenction
Kamau, M.A., Njuguna, M.I., Yusuf, J. A., Akama, V., (2013) “Agriculture and global warming” PLOS Medicine
Kamau, M.A., Njuguna, M.I., Yusuf, J. A., Akama, V., (2013) “Rotational farming as a business” The Journal of Infectious Diseases

This is the missing bit on the code snippet above

my ($authors, $year, $title, $journal) = split (/\t/, $lines);

    push @manuscripts, {
    authors => $authors,
    year => $year,
    title => $title,
    journal => $journal


#print "$title\n";
my $sql = "insert into manuscript($authors,$year,$title,$journal) 
values (?,?,?,?)";
my $stmt = $dbh->prepare($sql);

# disconnect from the MySQL database

Just send it to the browser as htm rather than executing it, or debug it if your ide supports debugguing.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.