This is the error that I get
SQLSTATE[42000]: Syntax error or access violation: 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 'anish123@gmail.com'.' GROUP BY email, date' at line 2 (SQL: SELECT email, date, min(time) AS checkedin, max(time) AS checkedout,( (TIME_TO_SEC(TIMEDIFF(max(time), min(time))) / 60) / 60) difference↵ FROM profile WHERE '. 1=1 and email like 'anish123@gmail.com'.' GROUP BY email, date)"
I am trying to filter data based on the email provided and on click of the button. The first query runs fine but I get error when I try to use the same where condition in second query.
$post = $request->all();
$email = $request->input('email');
$cond = ' 1=1 ';
if(!empty($post['email'])){
$cond .= " and email like '".$post['email']."'";
}
$qry = 'SELECT User_id, email, status, date, time FROM profile WHERE '.$cond.' ';
$data = DB::select($qry);
$sql=" SELECT email, date, min(time) AS checkedin, max(time) AS checkedout,( (TIME_TO_SEC(TIMEDIFF(max(time), min(time))) / 60) / 60) difference
FROM profile WHERE '.$cond.' GROUP BY email, date";
$previousdata = DB::select($sql);