Hi!

I have some problem. My database is created in Microsoft Access.

$sql = INSERT INTO Test (TestID,TeachID,LessonID,Year,Semester,Name,Time,Score,Password,Difficult) VALUES (1,'SW12','SW205','2000',2,'Test 1',60,120,'123456',5)

$result = odbc_exec($this->id,$sql);

Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in C:/Inetpub/wwwroot/PHP/class.odbc.inc.php on line 21.

What is happened in my source code?

Thanks for your help.

    I personally don't use Access, so I don't know if this applies to you, but I would try adding some "-quotes to the query (e.g. "INSERT INTO blahblahblah )" ) and definitely adding a semicolon ( ; ) at the end?? Hope that helps!

      As Lara said,

      $sql = "INSERT INTO Test (TestID,TeachID,LessonID,Year,Semester,Name,Time,Score,Password,Difficult) VALUES (1,'SW12','SW205','2000',2,'Test 1',60,120,'123456',5)";

      Note the quotes and semicolon at the end. You can always

      echo "$sql \n";

      in your code to see what is being tried.

        4 months later

        I had the same error and it took an hour to find out what the problem was.

        It turns out that the column name in my table seems to have been a reserved word.

        I was using "timestamp" as the column name and when I tried to insert a record I got the ODBC error 37000

        I changed the table column name in my MS Access database to "timestmp" and it worked.

          Write a Reply...