I keep getting the error message
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 '' at line 18
line 18 is AND tblMachine.ClientRef = ' ".$sr." ' ";
I have tested the variables, they are all OK up to this point, it is just getting the correct syntax for including the variable $sr in this query.
What I am doing is sending an e-mail to a list of users who fit within a certain criteria, so I am selecting users from a mysql database tblUser as follows
Create a list of Clients, and look at each of these clients in turn, and for each of these clients only show me the users who haven't sent me results this month.
Can anyone see where I am going wrong - I have gone over it time after time and cannot see anything......... Thanks
My code is
if ($FirstRemind == $today)
{
$query = "SELECT ClientId FROM tblClient WHERE ConcesRef = '$ConcesRef' ";
$result21 = mysql_query($query)
or die (mysql_error());
while($row21 = mysql_fetch_array($result21))
$ClientR[] = $row21["ClientId"];
foreach ($ClientR as $sr)
{
$sql = "SELECT tblUser.UEmail, tblUser.UName, tblMachine.MachineId, tblMachine.CommonName,
tblMachine.SerialNo, tblClient.ClientId, tblClient.CoName
FROM (tblClient INNER JOIN tblUser
ON (tblClient.ConcesRef = tblUser.ConcesRef)
AND (tblClient.ClientId = tblUser.ClientRef)
LEFT JOIN tblMachine
ON (tblUser.ConcesRef = tblMachine.ConcesRef)
AND (tblUser.ClientRef = tblMachine.ClientRef)
LEFT JOIN tblResults
ON (tblMachine.ConcesRef = tblResults.ConcesRef)
AND (tblMachine.ClientRef = tblResults.ClientRef)
AND (tblMachine.MachineId = tblResults.MachineRef)
AND tblResults.DateLogRef = '$DateLog'
AND tblResults.ResultsId Is Null
AND tblUser.Removed = '0000-00-00 00:00:00'
AND tblUser.AuthorityLevel >1
AND tblMachine.Removed = '0000-00-00 00:00:00'
AND tblMachine.ClientRef = ' ".$sr." ' ";
$getinfo = mysql_query($sql) or die (mysql_error());
while ($row22 = mysql_fetch_array($getinfo, MYSQL_ASSOC))
{
$UEmail = $row22["UEmail"];
$UName = $row22["UName"];
$MId = $row22["MachineId"];
$MName = $row22["CommonName"];
$serialno = $row22["SerialNo"];
$CliName = $row22["CoName"];
$CliRef = $row22["ClientId"];
$body2 = "email body text here ";
mail ("$UEmail", "subject", "$body", "FROM:X@x.com");
} //close while
} //close foreach
} // close if first remind is today