Link to home
Start Free TrialLog in
Avatar of Maxrespons
Maxrespons

asked on

Error in the SQL syntax - How do I solve this specific error?

I'm running a script that causes an SQL syntax error. However I am not good at MySQL at all, so I have no clue how to solve it.

Error:
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 'and a.merchant_id = 3 order by c.set_date' at line 1

The sql:
$sql = "select a.*,c.id as launched_id, b.subject, b.add_unsub_link, b.message, b.mail_type, d.subs_name, d.subs_email, d.id as subs_id, d.php_sess_id, b.id as message_id  from ".$CONFIG_TABLE_PREFIX."_auto_campaign_tb a,".$CONFIG_TABLE_PREFIX."_auto_messages_tb b,".$CONFIG_TABLE_PREFIX."_auto_launched_tb c,".$CONFIG_TABLE_PREFIX."_auto_subscribers_tb d where a.id = b.campaign_id and b.id = c.message_id and d.id = c.subscriber_id and c.set_date <='".date("Y-m-d H:i:s")."' and a.status = 1 and b.status = 1 and d.status = 1 and c.launched_status = -1 and d.validate = and a.merchant_id = ".$_SESSION["sess_ecommerce_merchant_id"]." order by c.set_date";

The database version is 5.0.67 community

Php version 5.2.6

Any else you need to point me in the right direction, or is it obvious what is wrong?


Here's the complete error message when running the file in my browser (FF3.0.6):

select a.*,c.id as launched_id, b.subject, b.add_unsub_link, b.message, b.mail_type, d.subs_name, d.subs_email, d.id as subs_id, d.php_sess_id, b.id as message_id from sc__auto_campaign_tb a,sc__auto_messages_tb b,sc__auto_launched_tb c,sc__auto_subscribers_tb d where a.id = b.campaign_id and b.id = c.message_id and d.id = c.subscriber_id and c.set_date <='2009-02-22 20:48:00' and a.status = 1 and b.status = 1 and d.status = 1 and c.launched_status = -1 and d.validate = and a.merchant_id = 3 order by c.set_dateYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and a.merchant_id = 3 order by c.set_date' at line 1
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you have this:

 and d.validate = and a.merchant_id

you are obviously missing the part to fill in the date...
Avatar of Maxrespons
Maxrespons

ASKER

Hmm..

d.validate : "d" is a table called "auto_subscribers_tb" - and "validate" is a field in there...

Where does the date come in?
My bad.

Should be d.validate =1 and etc.

Let me try. Got Mysql syntax error before too. I'll try fix this obviuos error first :-)
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, this is the correct sql (last part of it):
and d.validate = 1 and a.merchant_id = ".$_SESSION["sess_ecommerce_merchant_id"]." order by c.set_date";

:-)

I've been fighting some other errors the last days, and actually I made this error myself :-(

When I run the php file no ther's no error... :-)

Thanks for pointing this out for my tired eyes,,, I thought this had to do with me upgrading to MySql 5.. LOL
Hi. Thanks for helping! - I had a huger sql error earlier, and I had just made my own error in the fix. But was so tired I couldn't see it ;-)  - Thanks again!
I have asked the mods to upgrade the grade to an A. (I had misunderstood the A, B, C rating )

:-)