REG: dbi::errstr error.

REG: dbi::errstr error.

am 27.01.2006 10:57:41 von rajadilly

------=_Part_1373_15620750.1138355861304
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I have a cgi script adduser.cgi which collects the data from the user
through adduser.html. when i execute this script i encountered the error as
shown below.

Name "dbi::errstr" used only once: possible typo at adduser.cgi line 18.

the complete script of the adduser.cgi is shown below. Since i am new to
perl and mysql i cant able to find out the reason for the error. i will
thankful if you find out the reason for this.


the cgi script is

#!c:/perl/bin/perl -w

use CGI;
use DBI;
my $cgi=3Dnew CGI;

$name =3D $cgi->param("name");
$email=3D$cgi->param("email");
$phone=3D$cgi->param("phone");
$address=3D$cgi->param("address");
$username=3D$cgi->param("username");
$password=3D$cgi->param("password");

my $dbh=3DDBI->connect ("DBI:mysql:dvd","","autoraja")||
die "Error opening database: $DBI::errstr\n";
$sth=3D$dbh->prepare("insert into user(name, email, phone, address, usernam=
e,
password)
values($name, $email, $phone, $address, $username, $password)")=
;
$sth->execute()||die "Unable to insert the value: $dbi::errstr\n";
$dbh=3Ddisconnect();

print "Content-type: text/html\n\n";
print "";
print "CGI Process: $name\n";
print "";

if($name eq "")
{
print "

Invalid Name. Please Try Again.

";
exit (0);
}

print "The name is ", $name, "";
print "";



--
Friendly,
Raja.M

------=_Part_1373_15620750.1138355861304--

Re: dbi::errstr error.

am 27.01.2006 16:22:21 von scoles

try

$sth->execute() or die "Unable to insert the value: $dbi::errstr\n";

rather than

$sth->execute()||die "Unable to insert the value: $dbi::errstr\n";

I took the liberty of rewriting part of your code a little so it is more
readable and it is using params. This is a much more secure way to do CGI
programming.

my $sql="insert into user
(name, email, phone, address, username,password)
values(:p_name, :p_email, :p_phone, :p_address, :p_username,
:p_password)";

$sth=$dbh->prepare($sql);
$sth->bind_param(":p_name",$name);
$sth->bind_param(":p_email",$email);
$sth->bind_param(":p_phone",$phone);
$sth->bind_param(":p_address",$address);
$sth->bind_param(":p_username",$username);
$sth->bind_param(":p_password",$password);

$sth->execute() or die "Unable to insert the value: $dbi::errstr\n";
$dbh=disconnect();



"Dilly raja" wrote in message
news:a4f614df0601270157o65518d85s1e513ba62c57efc5@mail.gmail .com...
I have a cgi script adduser.cgi which collects the data from the user
through adduser.html. when i execute this script i encountered the error as
shown below.

Name "dbi::errstr" used only once: possible typo at adduser.cgi line 18.

the complete script of the adduser.cgi is shown below. Since i am new to
perl and mysql i cant able to find out the reason for the error. i will
thankful if you find out the reason for this.


the cgi script is

#!c:/perl/bin/perl -w

use CGI;
use DBI;
my $cgi=new CGI;

$name = $cgi->param("name");
$email=$cgi->param("email");
$phone=$cgi->param("phone");
$address=$cgi->param("address");
$username=$cgi->param("username");
$password=$cgi->param("password");

my $dbh=DBI->connect ("DBI:mysql:dvd","","autoraja")||
die "Error opening database: $DBI::errstr\n";
$sth=$dbh->prepare("insert into user(name, email, phone, address, username,
password)
values($name, $email, $phone, $address, $username, $password)");
$sth->execute()||die "Unable to insert the value: $dbi::errstr\n";
$dbh=disconnect();

print "Content-type: text/html\n\n";
print "";
print "CGI Process: $name\n";
print "";

if($name eq "")
{
print "

Invalid Name. Please Try Again.

";
exit (0);
}

print "The name is ", $name, "";
print "";



--
Friendly,
Raja.M

RE: dbi::errstr error.

am 27.01.2006 22:44:53 von Andy

> -----Original Message-----
> From: Dilly raja [mailto:rajadilly@gmail.com]
>
> I have a cgi script adduser.cgi which collects the data from the user
> through adduser.html. when i execute this script i
> encountered the error as
> shown below.
>
> Name "dbi::errstr" used only once: possible typo at
> adduser.cgi line 18.

"dbi::errstr" is not the same as "DBI::errstr".

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Re: dbi::errstr error.

am 28.01.2006 05:24:57 von ron

On Fri, 27 Jan 2006 10:22:21 -0500, John Scoles wrote:

Hi John

> $sth->execute()||die "Unable to insert the value: $dbi::errstr\n";

As Andy has pointed out, Perl is a case-sensitive language.

What follows is really off topic...

> I took the liberty of rewriting part of your code a little so it is
> more readable and it is using params. This is a much more secure
> way to do CGI programming.

Security is a huge topic. See the appropriate section in:

http://www.perl.org/CGI_MetaFAQ.html

I too have re-written the code (in its entirety), and you can download it=
from:

http://savage.net.au/Perl/quick-n-dirty.pl

I emphasize that this program is not what I would write under contract. It=
is
simply a vehicle for explaining a few issues, both with OP's (the original
poster's) code, and with your version.

Code highlights:

#=09o Use fatalsToBrowser during development.
# Programs in production should never die, of course
#=09o Storing the CGI form field names in an array,
# so when fields are added/deleted/renamed, that array
# is normally the only thing to edit
#=09o Use HTML::Template for sophisticated HTML management
#=09o Basing HTML generation in sub generate_html()
# on parameters without any reference to field names.
# This is the way fields can be added, deleted
# or renamed without changing the HTML template
#=09o Use 'CGI -> new()' instead of 'new CGI'.
# Your homework is to find out why that's best
#=09o sub clean_user_data() to sanitize data from the user
# before that data is used in any way.
# There are many methods for sanitizing data.
# See: http://www.perl.org/CGI_MetaFAQ.html
#=09o Use hashes %field_type and %data keyed by field name,
# which is the Perl way of doing things
#=09o Basing SQL generation on @field_name via @db_field
# so, as for CGI form fields, the column names in the
# SQL adjust automatically as fields are added, deleted
# or renamed. The SQL 'create table' statement can be
# built using the same technique
#=09o Use placeholders to get DBI to quote the field values
# appropriately
#=09o Setting the charset in the CGI header to add a little
# bit more security. Not a big point, but important
# nevertheless
#=09o In such a simple demo, using CGI::Application is not
# appropriate, but all people aspiring to be authors
# of sophisticated CGI scripts should be as familiar
# with that module as they should be with HTML::Template

--
Cheers
Ron Savage, ron@savage.net.au on 28/01/2006
http://savage.net.au/index.html
Let the record show: Microsoft is not an Australian company

Re: REG: dbi::errstr error.

am 28.01.2006 07:07:44 von jonathan.leffler

------=_Part_9016_22591643.1138428464495
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 1/27/06, Dilly raja wrote:
>
> I have a cgi script adduser.cgi which collects the data from the user
> through adduser.html. when i execute this script i encountered the error
> as
> shown below.
>
> Name "dbi::errstr" used only once: possible typo at adduser.cgi line 18.



The message is precise - and Perl is case-sensitive.


the complete script of the adduser.cgi is shown below. Since i am new to
> perl and mysql i cant able to find out the reason for the error. i will
> thankful if you find out the reason for this.
>
>
> the cgi script is
>
> #!c:/perl/bin/perl -w
>
> use CGI;
> use DBI;
> my $cgi=3Dnew CGI;
>
> $name =3D $cgi->param("name");
> $email=3D$cgi->param("email");
> $phone=3D$cgi->param("phone");
> $address=3D$cgi->param("address");
> $username=3D$cgi->param("username");
> $password=3D$cgi->param("password");
>
> my $dbh=3DDBI->connect ("DBI:mysql:dvd","","autoraja")||
> die "Error opening database: $DBI::errstr\n";
> $sth=3D$dbh->prepare("insert into user(name, email, phone, address,
> username,
> password)
> values($name, $email, $phone, $address, $username,
> $password)");
> $sth->execute()||die "Unable to insert the value: $dbi::errstr\n";
> $dbh=3Ddisconnect();
>
> print "Content-type: text/html\n\n";
> print "";
> print "CGI Process: $name\n";
> print "";
>
> if($name eq "")
> {
> print "

Invalid Name. Please Try Again.

";
> exit (0);
> }
>
> print "The name is ", $name, "";
> print "";
>
>
>
> --
> Friendly,
> Raja.M
>
>


--
Jonathan Leffler #include
Guardian of DBD::Informix - v2005.02 - http://dbi.perl.org
"I don't suffer from insanity - I enjoy every minute of it."

------=_Part_9016_22591643.1138428464495--