CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Help with MySQL insert record error?

 



CuzDesign
Deleted

May 11, 2001, 4:10 PM

Post #1 of 2 (512 views)
Help with MySQL insert record error? Can't Post

Hello,
I am working on learning to use mySQL and have run into an error when writing to the table in a database. Here is the code I am using as well as the error I receive when the form is submitted.

Code

Code
sub insert_entry { 
my ($dbh, $success, $name, $age, $email, $website, $comments,$time);

$dbh = DBI->connect("DBI:mysql:database=$serverDb Db;host=$serverName;port=$serverPort",$serverUser,$serverPass);
$name = param("name");
$age = param("age");
$email = param("email");
$website = param("website");
$comments = param("comments");
$time = "5:00";
$success = $dbh->do("INSERT INTO
$serverTabl(name,age,email,website,comments,time)
VALUES(?,?,?,?,?,?)", undef, $name, $age, $email, $website, $comments, $time);
$dbh->disconnect;
if($success != 1) {
return "Sorry, the database was unable to add your entry.
Please try again later.";
} else {
return;
}
}

Here is the error I receive:

Code
Software error: 
Can't call method "do" without a package or object reference at dbtest.cgi line 69.

Any help to why I am getting this error would be greatly appreciated.

Thanks in advance,
Ray



CuzDesign
Deleted

May 12, 2001, 1:14 PM

Post #2 of 2 (502 views)
Re: Help with MySQL insert record error? [In reply to] Can't Post

For those interested I fixed the problem by changing the
code to the following:


Code
sub insert_entry {      
my ($dbh, $success, $name, $age, $email, $website, $comments,$time);

$dbh = DBI->connect("DBI:mysql:$serverDb",$serverUser,$serverPass) or die "Unable to connect to guestbook database: $dbh->errstr\n";
$name = param("name");
$age = param("age");
$email = param("email");
$website = param("website");
$comments = param("comments");
$time = time;
$success = $dbh->do("INSERT INTO $serverTabl(name,age,email,website,comments,time)
VALUES('$name','$age','$email','$website','$comments','$time')") or die "Unable to write information to guestbook database: $dbh->errstr\n";
$dbh->disconnect;
if($success != 1) {
return "Sorry, the database was unable to add your entry. Please try again later.";
} else {
return;
}
}

Thank you,
Ray


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives