[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-02-22
8
Medium Priority
?
233 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:Maxrespons
  • 5
  • 2
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 23706205
you have this:

 and d.validate = and a.merchant_id

you are obviously missing the part to fill in the date...
0
 

Author Comment

by:Maxrespons
ID: 23706244
Hmm..

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

Where does the date come in?
0
 

Author Comment

by:Maxrespons
ID: 23706263
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 :-)
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 23706268
what I mean is: there is no value specified for the condition:



 and d.validate = <some value> <<<< this part is missing
 and a.merchant_id = <some value>
0
 

Author Comment

by:Maxrespons
ID: 23706302
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
0
 

Author Closing Comment

by:Maxrespons
ID: 31549836
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!
0
 

Author Comment

by:Maxrespons
ID: 23709508
I have asked the mods to upgrade the grade to an A. (I had misunderstood the A, B, C rating )

:-)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question