Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: A seeming random error.

by Russ (Deacon)
on Nov 29, 2000 at 23:36 UTC ( [id://43985]=note: print w/replies, xml ) Need Help??


in reply to A seeming random error.

Look at the actual strings you are sending to $dbh->do. If the user has a single-quote in a field (like dated, issuedby, etc), the SQL string will be bad.
my $Str = "Insert into City_Policies (ID, DATE_CREATED, ISSEDBY, SUBJE +CT) values ('$policynumber', '$DATE_CR', '$ISSUEDBY', '$newsubject')"; warn $Str; $dbh->do($Str) or print "I died";
This may be a good reason to go ahead and build statement handles and use placeholders. DBI will handle embedded quotes for you.

BTW, may I suggest a stylistic change? ;-)

my $POLICY1 = ""; my $DATE_CR = ""; my $POLICY2 = ""; my $POLICY3 = ""; my $POLICY4 = ""; my $POLICY5 = ""; my $POLICY6 = ""; my $ISSUEDBY = ""; my $SUBJECT =""; my $PURPOSE = ""; $POLICY1 =~s/<br>/\n/g; $POLICY2 =~s/<br>/\n/g; $POLICY3 =~s/<br>/\n/g; $POLICY4 =~s/<br>/\n/g; $POLICY5 =~s/<br>/\n/g; $POLICY6 =~s/<br>/\n/g; $POLICY1 =~s/<BR>/\n/g; $POLICY2 =~s/<BR>/\n/g; $POLICY3 =~s/<BR>/\n/g; $POLICY4 =~s/<BR>/\n/g; $POLICY5 =~s/<BR>/\n/g; $POLICY6 =~s/<BR>/\n/g;
can be more succinctly written as:
my ($IDNUM, $ISSUEDBY, $DATE_CR, $SUBJECT, $PURPOSE, $POLICY1, $POLICY2, $POLICY3, $POLICY4, $POLICY5, $POLICY6) = $sth->fetchrow_array; $_ ||= '' for ($DATE_CR, $ISSUEDBY, $SUBJECT, $PURPOSE); $_ ||= '', s/<br>/\n/ig for ($POLICY1, $POLICY2, $POLICY3, $POLICY4, $POLICY5, $POLICY6) +;
Far fewer lines, and you get to use the cool ||= and postfix for operators! :-)

Russ
Brainbench 'Most Valuable Professional' for Perl

Replies are listed 'Best First'.
Re: Re: A seeming random error.
by BigJoe (Curate) on Nov 30, 2000 at 02:30 UTC
    Thanks I really didn't think about grouping it like that.

    --BigJoe

    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://43985]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-18 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found