Hello,
What I am trying to do is insert form fields into a mySQL database
table by using them in an array. I have the array setup properly it collects
all the fields but when I try to insert it into the table I get and error.
Below
is the information on what I am running as well as the code snippet and
error
message. Any help would be greatly appreciated. The reason for using an
array
is because there is 32 fields and I would rather use it this way then to say
my $field = param('field'); for 32 lines.
Environment Information:
mySQL Version: 3.23.33
Server Apache Version: 1.3.19
OS: Windows
DBI Version: Most current
DBD::mysql version: most current
Script:
Top:
use strict;
use CGI::Carp "fatalsToBrowser";
use CGI ":all";
use DBI;
my $servname = "localhost";
my $servuser = "inventory";
my $servpass = "inventory";
my $db = "inventory";
my $tbl = "vehicles";
my ($dbh);
$dbh = DBI->connect("DBI:mysql:$db",$servuser,$servpass) or die "Unable to
connect to inventory database: $dbh->errstr\n";
my $obj = new CGI;
my @values = map { $obj->param($_) } $obj->param();
my @all = join(",", @values);
foreach (@all) {s/addvehicle,//;}
my $all = "@all";
my $success = $dbh->do("INSERT INTO $tbl VALUES $all") or die "Unable to
write information to inventory database: $dbh->errstr\n";
$dbh->disconnect;
if($success != 1) {
print header, start_html("Entry Added");
print "Sorry, the database was unable to add your entry. Please try
again
later.";
} else {
print header, start_html("Entry Added");
print "Information Added\n";
}
That is what I am using I get an error at the my $success = $dbh->do("INSERT
INTO $tbl VALUES $all") or die "Unable to write information to inventory
database: $dbh->errstr\n"; process.
Error Message:
Unable to write information to inventory database:
DBI::db=HASH(0x1a94a1c)->errstr
I have tried every way possible I can think of and I cannot get it to work
at all.
Any help with this would be greatly appreciated.
Thanks in advance,
Ray