If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Inconsistent Syntax Error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-04, 13:48
mvarian mvarian is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Inconsistent Syntax Error

I have the chunk of code below. The exact same code with just a slightly different query to access a different database works fine in another script elsewhere on the site, but for some reason this page alone always throws the error:

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in C:\Inetpub\wwwroot\fuel\test.php on line 29
INSERT INTO mreports (Year, Month, File, Order) VALUES ('2003', 'Jan', 'monthlyreports/test.pdf', '1')
Record not added, an error occurred : 37000

any ideas???? I'm stumped!

Thanks

PHP Code:
// connect to access database
                    
$cfg_dsn "DRIVER=Microsoft Access Driver (*.mdb);
                    DBQ=C:/Inetpub/wwwroot/monthly_fuel.mdb;
                    UserCommitSync=Yes;
                    Threads=3;
                    SafeTransactions=0;
                    PageTimeout=5;
                    MaxScanRows=8;
                    MaxBufferSize=2048;
                    php DriverId=281;
                    DefaultDir=C:/ProgramFiles/CommonFiles/ODBC/DataSources"
;

                    
$cfg_dsn_login "";
                    
$cfg_dsn_mdp "";
            
                
$connection odbc_connect($cfg_dsn,$cfg_dsn_login,$cfg_dsn_mdp);
                
$command "INSERT INTO mreports (Year, Month, File, Order) VALUES ('2003', 'Jan', 'monthlyreports/test.pdf', '1')";
                if(
odbc_exec($connection$command)) { 
Reply With Quote
  #2 (permalink)  
Old 12-07-04, 20:24
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
You are better off to ask this in another forum since this one is for mysql queries. there is a forum for Microsoft SQL Server and Other forums where you are likely to ge an answer.
Reply With Quote
  #3 (permalink)  
Old 12-08-04, 03:36
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
I'd of thought the PHP forum would be more appropriate

but in the db how is the column year defined, numeric or alpha?, the script suggests alpha
Reply With Quote
  #4 (permalink)  
Old 12-09-04, 12:32
mvarian mvarian is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Sorry if I misplaced this, my reasoning was that the error was a sql statement syntax error so it would've fallen under the mysql category.

The year field is defined as a number, as is the Order, everything else is numeric. I've tried removing the quotes and I get the same error, and actually in a working statement I have elsewhere for another DB and table I use the quotes and it works...
Reply With Quote
  #5 (permalink)  
Old 12-09-04, 13:15
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
Good practise would indocate the that you inform the db that its a string by using quotes, a number doen't use quotes.

I'd try rerunning the query by removing all quotation marks form numeric fields and see what happens.

It is entirely possible that PHP may make decisions for you as to what the column type should be, but why rely on someone else. If its numeric make it explicitly numeric
HTH
Reply With Quote
  #6 (permalink)  
Old 12-09-04, 13:51
White Knight White Knight is offline
Registered User
 
Join Date: Dec 2004
Location: York, PA
Posts: 95
Smile Well Well Well

You just about managed to get a full row of Reserved Words here!

OK so you can use reserved words but you have to enclose them in [ ]

$command = "INSERT INTO mreports ([Year], [Month], [File], [Order]) VALUES ('2003', 'Jan', 'monthlyreports/test.pdf', '1')";

Reply With Quote
  #7 (permalink)  
Old 12-09-04, 14:46
mvarian mvarian is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Ah that was it!!! (reserved words)

THANK YOU! I've had a headache for a week over this!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On