user2350122 user2350122 - 22 days ago 8
MySQL Question

Compare 2 emails MySQL error 1064

I am very stuck in one small comparison in

MySQL
. Every time I want to compare two emails in
php
from MySQL database i am getting an error (1064). Here is my query:

$query =
select(array('a.dtstart','a.cal_id','b.name','a.email'))
from('#__pbbooking_events AS a')
join('INNER', '#__pbbooking_cals AS b ON (a.cal_id = b.id)')
where('a.email = ' . $user->email)
where(' a.dtstart>'. $query->currentTimestamp())
order('a.dtstart ASC');


$user
just has information of the currently logged user.

This is the error that appears.


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 '@RET.RU AND A.DTSTART>CURRENT_TIMESTAMP() ORDER BY A.DTSTART
ASC' AT LINE 4


If I delete the comparison of emails everything works perfectly. I have read somewhere that the problem is the @ sign but how can I make this comparison then?

Any help is much appreciated!

Answer

$user->email is string so you need to use ' single brackets with email.

Try below

$query
    ->select(array('a.dtstart','a.cal_id','b.name','a.email'))
    ->from('#__pbbooking_events AS a')
    ->join('INNER', '#__pbbooking_cals AS b ON (a.cal_id = b.id)')
    ->where("a.email = '" . $user->email. "'") // $user->email is string
    ->where(' a.dtstart > '. $query->currentTimestamp())
    ->order('a.dtstart ASC');