I think you missed his point Bill.

I imagine he intends to use it in a SQL query, but is
just showing it in a single print statement to isolate
the error.

try using vars in list context 
%params = $q->Vars;

or use the quote method on the param call like:
$dbh->quote(param('abc'));    

Job   


--- William R Ward <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] (Joseph Xu) writes:
> > The following test script has strange behavior.  
> It may relate
> > to CGI::Vars. please advice.
> > 
> > Thanks
> > 
> > #!/usr/bin/perl
> > 
> > use DBI;
> > use CGI;
> > 
> > my $dbh = DBI->connect("dbi:mysql:wirepoll01",
> "UID", "PWD");
> > my $q = new CGI;
> > 
> > $q->param('abc' => 'teststring');
> > $p = $q->Vars;
> > print $dbh->quote( $p->{'abc'} );       # WHY
> print 'NULL' ????????
> > 
> > $pp = {'abc' => 'teststring'};
> > print $dbh->quote( $pp->{'abc'} );      # but this
> print '\'teststring\''
> > 
> > $dbh->disconnect;
> 
> The DBI::quote function is not intended for CGI,
> it's intended for the
> database.  In a SQL statement, if a string contains
> single quotes, you
> need to replace them with \' or '' (depending on the
> database's
> rules), and if a value is undefined, the database
> equivalent is NULL.
> 
> The reason $p->{'abc'} is not working as you would
> expect is a CGI
> question, not a DBI one.  Try printing it without
> the $dbh->quote()
> function call, and see what the results are.  Also
> check
> defined($p->{'abc'}) and exists($p->{'abc'}).
> 
> If you are interested in "quoting" characters for
> display in HTML, use
> CGI::escapeHTML.  For quoting characters in URLs,
> use CGI::escape or
> the URI module.
> 
> --Bill.
> 
> -- 
> William R Ward            [EMAIL PROTECTED]         
> http://www.wards.net/~bill/
>
-----------------------------------------------------------------------------
>      If you're not part of the solution, you're part
> of the precipitate.


__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

Reply via email to