I think that you are having problems because you are using a reference to
the array.  The reference won't evaluate to the values in your array, but
rather to the location of your actual array.  You probably need to
dereference the array before you use it in the SQL statement. However You
probably don't even need to make a reference to it in the first place.

Joe Grastara
Project Assistant
Digital Media Center
The Skirball Institute Of Biomolecular Medicine
New York University Medical Center
540 First Ave., New York City, NY 10016 USA 
[EMAIL PROTECTED]
http://www.med.nyu.edu/graphics


On Wed, 16 May 2001, Ray Cuzzart II wrote:

> 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
> 

Reply via email to