http://qs321.pair.com?node_id=305927


in reply to Mysql syntax error from DBI

Since "drain cleaner" is two words, it should be quoted. An easy way to solve this and similar problems is to use placeholders. Something like:
my $sth =$dbh ->prepare("UPDATE products set pname=? and unit=? and q +ty=? and cost=? WHERE id = ?"); $sth->execute($pname, $unit, $qty, $cost, $id);
should do the trick. The question marks are replaced by the values passed to execute. For more information, see DBI.

Are you sure it was a book? Are you sure it wasn't.....nothing?

Replies are listed 'Best First'.
Re: Re: Mysql syntax error
by dbwiz (Curate) on Nov 10, 2003 at 19:00 UTC
    my $sth =$dbh ->prepare("UPDATE products set pname=? and unit=? and qty=? and cost=? WHERE id = ?");
    should do the trick.

    No. It shouldn't.

    The SQL syntax is wrong (see meetraz's answer.