RE: [PHP-DB] Spot the deliberate mistake...
| From: | Norland, Martin | Date: | Thu, 16 Dec 2004 17:07:48 +0000 |
| Subject: | RE: [PHP-DB] Spot the deliberate mistake... | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-37719@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Mark Benson [mailto:markbenson@mac.com]
> The following SQL statement returns an error. What is wrong with it?
The error is stated as being near 'ON DUPLICATE KEY
> UPDATE foo_no='$data[1]', alt_no='$data[2]', descript='$data[3]',
> pr'
>
> "INSERT INTO
foobar2 SET part_no='$data[0]',
> foo_no='$data[1]',
alt_no='$data[2]', descript='$data[3]', price='$data[4]',
> unit_sale='$data[5]', unit_issue='$data[6]', weight='$data[7]',
brand='$data[8]', nla_tag='0' ON DUPLICATE KEY UPDATE
> foo_no='$data[1]', alt_no='$data[2]', descript='$data[3]',
price='$data[4]', unit_sale='$data[5]', unit_issue='$data[6]',
weight='$data
> [7]', brand='$data[8]', nla_tag='0'"
You shouldn't specify your data to be inserted again after the 'ON
DUPLICATE KEY UPDATE' statement.
"INSERT INTO foobar2 SET part_no='$data[0]',
foo_no='$data[1]',
alt_no='$data[2]', descript='$data[3]', price='$data[4]',
unit_sale='$data[5]', unit_issue='$data[6]', weight='$data[7]',
brand='$data[8]', nla_tag='0' ON DUPLICATE KEY UPDATE;"
It's implicit that you use the same data regardless, you're saying "if
it's already there, just do an update statement with the data already
provided".
Cheers,
- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.