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

Somethings not rightwith my MySQL do()

by andrew (Acolyte)
on Jul 20, 2002 at 00:35 UTC ( #183515=perlquestion: print w/ replies, xml ) Need Help??
andrew has asked for the wisdom of the Perl Monks concerning the following question:

if(param('page') eq "yes") { $dbh->do("UPDATE category SET name='$cat' AND view_cats_prod='yes +' AND description='$des' WHERE id='$id'") or die $dbh->errstr; } else { $dbh->do("UPDATE category SET name='$cat' AND view_cats_prod='no' + AND description='$des' WHERE id='$id'") or die $dbh->errstr; }
I do this and it sets the name to "0" and it wont change the rest??

Comment on Somethings not rightwith my MySQL do()
Download Code
Re: Somethings not rightwith my MySQL do()
by tstock (Curate) on Jul 20, 2002 at 01:17 UTC
    Something else is probably wrong, this code seems "runable" to me. Check what is $cat before running the query. You should also consider using placeholders:
    my $sql = 'UPDATE category SET name=? AND view_cats_prod=? AND descrip +tion=? WHERE id=?' my $y; if (param('page') eq "yes") { $y = 'yes'; } else { $y = 'no'; } $dbh->do($sql, undef, $cat, $y, $des, $id) || die $dbh->errstr;
    Tiago

    Update: Without more information all I can do is toss wild guesses. Did you commit if you need to? Is the field of the right type for the value you are inserting?
      nope plaholder do same-thing
        Add some basic debugging code to your script that prints out the value of $cat (and any other variable) before using it. I would suspect that this variable is not being properly set prior to being used in this query.

        And note that the placeholder suggestion is also one of safety: if you are using variables that are provided by the user directly in your SQL, keep in mind that users can put single-quotes and SQL code in this variable and execute arbitrary queries against your database through insecure code like this.

        use strict and taint-checking (perl -wT) when dealing with potentially unsafe data and Perl will (usually) get your attention when you try and do something that someone else could exploit.

Re: Somethings not rightwith my MySQL do()
by gav^ (Curate) on Jul 20, 2002 at 01:45 UTC
    You've got the UPDATE syntax wrong, it should be like:

    UPDATE category SET name = ?, view_cats_prod = 'yes' WHERE id = ?

    You should really test your SQL statements before you put them into your perl code.

    Documentation can be found (for mysql) here.

      Thank you I though you could use AND in SET I gues its commas thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://183515]
Approved by gav^
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-08-23 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls