my question should be very easy to fix but I can't find the syntax error that my db interface throws at me. The following code is used to update the password of an existing user in a timetrackingtool
.
I checked all the tables and field names, they all are right.
The SQL query code:
$query = ('UPDATE tblMitarbeiterUUID SET tblMitarbeiterUUID.dtPassword="' . $pwd . '" '.
'INNER JOIN arbeiter '.
'ON tblMitarbeiterUUID.idMitarbeiterUUID=arbeiter.fidMitarbeiterUUID ' .
'WHERE arbeiter.id=' . $userID)
Echo of this query:
UPDATE tblMitarbeiterUUID SET tblMitarbeiterUUID.dtPassword="7687225fde7aad38f4c005ad4b5cdd5a" INNER JOIN arbeiter ON tblMitarbeiterUUID.idMitarbeiterUUID=arbeiter.fidMitarbeiterUUID WHERE arbeiter.id=1
Error I get when trying to run the query directly on the db:
SQL error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM tblMitarbeiterUUID INNER JOIN arbeiter ON tblMitarbeiterUUID.ifMitarbeiterUUID=arbeiter.fidMitar...' at line 1
In my research I saw some people using a FROM
in a UPDATE
statement with an INNER JOIN
. I tried it with a FROM
but I get the same error as above.
Thanks for your help in advance. Best Regards, Luca.
correct syntax (edited after I got the correct answer):
'UPDATE tblMitarbeiterUUID x '.
'JOIN arbeiter y ON x.idMitarbeiterUUID = y.fidMitarbeiterUUID ' .
'SET x.dtPassword="' . $pwd . '" ' .
'WHERE y.id=' . $userID
This is valid syntax:
UPDATE tblMitarbeiterUUID x
JOIN arbeiter y
ON x.idMitarbeiterUUID = y.fidMitarbeiterUUID
SET x.dtPassword="A"
WHERE y.id=1