2

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
1
  • Note also that you're open to sql injection Commented Jul 9, 2018 at 6:52

1 Answer 1

3

This is valid syntax:

UPDATE tblMitarbeiterUUID x

JOIN arbeiter y
ON x.idMitarbeiterUUID = y.fidMitarbeiterUUID 

SET x.dtPassword="A"  

WHERE y.id=1
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot this was the answer I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.