In a timetracking application I'm developing right now this query fails and I can't figure out why. The Var $userID has the value 1 in it what is right. The naming of each table and field should be correct because I checked it like four times.
query:
$query= 'SELECT arbeiter.id AS id,'.
'tblMitarbeiterUUID.dtLastname AS dtLastname, ' .
'tblMitarbeiterUUID.dtFirstname AS dtFirstname, ' .
'FROM arbeiter, tblMitarbeiterUUID ' .
'WHERE ' .
'arbeiter.id =' . $userID .' ' .
'AND arbeiter.start_date < NOW() '.
'AND (arbeiter.end_date=\"0000-00-00 00:00:00\" '.
'OR arbeiter.end_date > NOW())';
If I echo the Query I get this:
SELECT arbeiter.id AS id,tblMitarbeiterUUID.dtLastname AS dtLastname, tblMitarbeiterUUID.dtFirstname AS dtFirstname, FROM arbeiter, tblMitarbeiterUUID WHERE arbeiter.id =1 AND arbeiter.start_date < NOW() AND (arbeiter.end_date=\"0000-00-00 00:00:00\" OR arbeiter.end_date > NOW())
The error I get when trying to paste query directly into my sql tool:
SQL syntax error near :"FROM arbeiter, tblMitarbeiterUUID WHERE arbeiter.id =1 AND arbeiter.start_date <"
I bet it should be an easy fix for one of you guys. Or is my approach to this wrong and should I try it with an INNER JOIN ?
Thanks in advance
ERRORS found the comma after dtFirstname and the backslashes to escape the " were the problems! Now everything works fine.