I am new to mysql and a novice at perl. My program works except for the
write to the database. when I enter data in the form it does put it in the
text file. The database select does read back the two records I manually
inserted. But I am not able to find out why my insert does not work. I check
the field names in the form and they corespond to the fields in the
database.
Error message are:

CGI Error
The specified CGI application misbehaved by not returning a complete set of
HTTP headers. The headers it did return are:


Scalar found where operator expected at
C:\Inetpub\wwwroot\cgi-bin\memberv2.cgi line 30, near ""INSERT INTO members
VALUES("$membername"
 (Missing operator before $membername?)
String found where operator expected at
C:\Inetpub\wwwroot\cgi-bin\memberv2.cgi line 30, near "$membername",""
 (Missing operator before ","?)
Scalar found where operator expected at
C:\Inetpub\wwwroot\cgi-bin\memberv2.cgi line 30, near "","$address"
 (Missing operator before $address?)
String found where operator expected at
C:\Inetpub\wwwroot\cgi-bin\memberv2.cgi line 30, near "$address",""
 (Missing operator before ","?)
Scalar found where operator expected at
C:\Inetpub\wwwroot\cgi-bin\memberv2.cgi line 30, near "","$city"
 (Missing operator before $city?)
String found where operator expected at C:\Inetpub\wwwroot\c

Below is the code:

#!c:\perl\bin\perl

use DBI();
print "Content-type:text/html\n\n";

#Parse the form data
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$buffer);
foreach $pair (@pairs){
 ($name, $value) = split(/=/, $pair);
 $value =~ tr/+/ /;
 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
 $value =~ s/\n/ /g;
 $value =~ s/\r/ /g;
 $value =~ s/\cM/ /g;
 $name =~ tr/+/ /;
 $name =~ tr/_/ /;
 $FORM{$name} = $value;
 }
$blank= " ";

#Connect to database members.

 $database = "members";
 $table = "members";

 $dbh = DBI->connect("DBI:mysql:$database")or
dienice("Can't connect:$DBI::errstr");

$dbh->do("INSERT INTO members
VALUES("$membername","$address","$city","$state","$zipcode","$phonenumber")"
);

# Save the data to a file
open(OUTF, ">>member.txt") or dienice("Couldn't open visitation.txt for
writing: $!");

#Lock the file
#flock(OUTF, 2);
#Reset pointer
seek(OUTF,0,2);

# Print form data
foreach $key (keys(%FORM)) {
 print  OUTF "$key = $FORM{$key}\n";
}

print OUTF "$blank\n";
close(OUTF);

#Acknowledge receiving form

print <<EndHTML;
<html><head><title>Member Information</title></head>
<body>
<h2>Thank You</h2>
Thank you for adding information about a member. Your information was
entered into the database and a txt file.<p>

</body></html>

EndHTML

#Connect to database members retrieve information.

 $database = "members";
 $table = "members";

 $dbh = DBI->connect("DBI:mysql:$database")or
dienice("Can't connect:$DBI::errstr");

$sth = $dbh->prepare("select
membername,address,city,state,zipcode,phonenumber from members")or
dienice("Can't prepare statement:",$dbh->errstr);

$rv = $sth->execute();

while (($membername,$address,$city,$state,$zipcode,$phonenumber) =
$sth->fetchrow_array){
    print "$membername - $address - $city - $state - $zipcode -
$phonenumber<p>\n";
 }
$sth->finish();
# Disconnect the Database
$dbh->disconnect();

#The dienice subroutine, for handling errors.
sub dienice {
my($errmsg) = @_;
print "<h2>Error</h2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";
exit;
}

exit;

Russ Fineman



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to