Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2004
    Posts
    3

    Unanswered: 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)) { 

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    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.

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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

  4. #4
    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...

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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

  6. #6
    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')";


  7. #7
    Join Date
    Dec 2004
    Posts
    3
    Ah that was it!!! (reserved words)

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •