Hi folks, I have a PHP class that creates a SQL query based on values entered from a form. I'm getting
Incorrect syntax near the keyword 'WHERE'. ) )
Here is my code. The problem is occurring around each of the WHERE clauses, (already dealing with SQL injections btw).
if($from != ''){
$from = date('Y-m-d H:i:s',strtotime($from));
}
if($to != ''){
$to = date('Y-m-d H:i:s',strtotime($to));
}
$tsql = "SELECT COUNT(tblBackupArchive.StatusID) AS total, tblBackupArchive.StatusID ".
"FROM tblBackupArchive INNER JOIN ".
"tblBackup ON tblBackupArchive.BackupID = tblBackup.BackupID ".
"GROUP BY tblBackupArchive.StatusID, tblBackup.ClientID ";
if($from != '' && $to !=''){
$tsql .= "WHERE (tblBackupArchive.BackupDate BETWEEN '" . $from ."' AND '" . $to . "') ";
}
if($from != '' && $to=''){
$tsql .= " WHERE (tblBackupArchive.BackupDate > '" . $from ."') ";
}
if($to != '' && $from = ''){
$tsql .= " WHERE (tblBackupArchive.BackupDate < '" . $to ."') ";
}
if(isset($bmsid)){
$tsql .= "HAVING (tblBackup.ClientID = " . $bmsid . ")";
}
I'm terrible with these syntax errors :(
Can someone help me out?
Jonesy