I can't seemed to insert all the fields entered by the user into the database. It always gave me this error "The following error occurred : Can't call method "prepare" on an undefined value at D:\fmp\Web\cgi-bin\dndregi
stration.c
gi line 73. "
I can't seemed to resolve it, can anyone help it?
The cgi file is as follows :-
#!/usr/bin/perl
print "Content-type:text/html\n\
n";
use Mail::Sender;
use CGI qw(:standard); # Must be used to get the param() function
use DBI; # Must be used for connecting to databases engine
$SIG{__DIE__} = \&Error_Msg;
sub Error_Msg {
$msg = "@_";
print "The following error occurred : $msg\n";
exit;
}
$name = param("name");
$contact_no = param("contact_no");
$email = param("email");
$attending = param("attending");
$mealset = param("mealset");
($sec,$min,$hour,$mday,$mo
n,$year,$w
day,$yday,
$isdst) = localtime();
$mon += 1; # Ajust the month to a 1 to 12 format instead of a 0 to 11 format
$year += 1900; # $year is nb of years since 1900, so add up to 1900
$currentDate = "$year/$mon/$mday $hour:$min:$sec";
$myEmail1 = 'abc@hotmail.com';
$mySMTPserver = '172.29.91.18';
sub template {
local(*FILE); # filehandle
local($file); # file path
local($HTML); # HTML data
$file = $_[0] || dienice("Template : No template file specified\n");
open(FILE, "<$file") || die("Template : Couldn't open $file : $!\n");
while (<FILE>) { $HTML .= $_; }
close(FILE);
$HTML =~ s/\$(\w+)/${$1}/g;
return $HTML;
}
ref ($sender = new Mail::Sender { from => $email,
smtp => $mySMTPserver})
or die("Error($sender) : $Mail::Sender::Error\n");
$sender->Open({to => $myEmail1, subject => "Annual Dinner & Dance 2000 - Registration Form"});
$sender->SendLine("This request form was sent on: " . $currentDate);
$sender->Send("\n");
$sender->SendLine("Applica
nt Information");
$sender->SendLine("-------
----------
----------
----------
---");
$sender->SendLine("Name : " . $name);
$sender->SendLine("Contact
Number : " . $contact_no);
$sender->SendLine("Attendi
ng : " . $attending);
$sender->SendLine("Choice of set : " . $mealset);
$sender->Send("-----------
----------
----------
---------"
);
$sender->Close;
#-------------------------
----------
----------
----------
----------
-------
# This section is for appending the data to the database.
sub new_record {
# This function add a record to the db
my ($currentDate, $name, $email, $contact_no, $attending, $mealset) = @_; # Get arguments
my ($dbh, $sth, $sql, $rv);
$dbh = DBI->connect( q{DBI:ODBC:dnd_DB},
{RaiseError => 1,
PrintError => 1,
AutoCommit => 1} );
$sql = q{INSERT INTO tblregistration VALUES (?,?,?,?,?,?)};
$sth = $dbh->prepare( $sql );
$ rv = $sth->execute($currentDate
, $name, $email, $contact_no, $attending, $mealset);
my $success = 1;
$success &&= $rv;
$dbh->disconnect;
return $success;
}
# This function appends the data to the db
if (new_record($currentDate, $name, $email, $contact_no, $attending, $mealset)) {
#-------------------------
----------
----------
----------
----------
-------
# This section prints a thanks-for-being-so-nice message
print &template("Adnd/2000/thank
you1.html"
); #Prints the content of this html file
}