RE: Spot the deliberate mistake...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Mark Benson [mailto:markbenson@xxxxxxx] 
> 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.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux