I was trying to use the ON UPDATE DUPLICATE KEY clause for the first time, following this link
SQL - IF EXISTS UPDATE ELSE INSERT INTO
and I'm getting an error in my sql syntax:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''AJAY KUMAR')' at line 2 The SQL being executed was: INSERT INTO fee_acc_balance (guardian_name, account_no, paid_amount, due, days_overdue, total_fees, updated_on) VALUES ('AJAY KUMAR', '10', 0, 12550, 0, 12550, '2017-02-10 21:28:05') ON DUPLICATE KEY UPDATE guardian_name = VALUES ('AJAY KUMAR') Error Info: Array ( [0] => 42000 [1] => 1064 [2] => You have an error..
The unique key in my case is account_no
, and this is my sql :
INSERT INTO fee_acc_balance (guardian_name, account_no, paid_amount, due, days_overdue, total_fees, updated_on)
VALUES ('$father_name', '$account->account_no', $payments, $sum, 0, $sum,'$now')
ON DUPLICATE KEY UPDATE guardian_name = VALUES ('$father_name')
Where does the error lie?