4 Replies - 364 Views - Last Post: 14 February 2017 - 06:56 AM

#1 hanadori  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-July 12

I get Syntax Error using IF on UPDATE query

Posted 14 February 2017 - 04:29 AM

Need help... Tested on myphpadmin using XAMPP. It seems my code is correct but I do get this syntax error.
IF (SELECT `itemCode` FROM `tbl_orderquotation_draft` WHERE `orderQuotationCode`  = "OQ-81413" AND `itemCode` = "itm-441179")
= "itm-441179"
THEN 
UPDATE `tbl_orderquotation_draft`
SET 
`orderQty` = "10",
`totalAmount` = "10"
WHERE `orderQuotationCode` = "OQ-81413" 
AND `itemCode` = "itm-441179";
END IF


Unrecognized statement type. (near "IF" at position 0)

Is This A Good Question/Topic? 0
  • +

Replies To: I get Syntax Error using IF on UPDATE query

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4128
  • View blog
  • Posts: 13,020
  • Joined: 08-June 10

Re: I get Syntax Error using IF on UPDATE query

Posted 14 February 2017 - 05:37 AM

just drop the IF(). when the uppdate's conditions don't match, no update is executed.

Additionally, IF() doesn't have THEN (CASE does).

And you also can't start a statement with a control flow function.
Was This Post Helpful? 1
  • +
  • -

#3 hanadori  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-July 12

Re: I get Syntax Error using IF on UPDATE query

Posted 14 February 2017 - 05:49 AM

View PostDormilich, on 14 February 2017 - 05:37 AM, said:

just drop the IF(). when the uppdate's conditions don't match, no update is executed.

Additionally, IF() doesn't have THEN (CASE does).

And you also can't start a statement with a control flow function.


thank you. i will try case then :)
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4128
  • View blog
  • Posts: 13,020
  • Joined: 08-June 10

Re: I get Syntax Error using IF on UPDATE query

Posted 14 February 2017 - 05:54 AM

ther is no need for you to use IF or CASE.
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: I get Syntax Error using IF on UPDATE query

Posted 14 February 2017 - 06:56 AM

Forget what you are doing now, what are you trying to do?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1