odbc SQL syntax error

Hi.

I recently created a new DB on my computer using MS Access. The DB is saved as a .mdb file. I also defined a System DSN directing to this DB, in “MS ODBC Source Administrator”. That’s all it takes, right?
When I try fetching information from a table it works. Here’s the code:

[code]//displaying array:
$query = odbc_exec($link, “SELECT * FROM contact”) or die (odbc_errormsg());

while ($row = odbc_fetch_array($query)) {
echo ‘DateTime: ‘.$row[‘DateTime’].’
’;
echo ‘FullName: ‘.$row[‘FullName’].’
’;
echo ‘PhoneNo: ‘.$row[‘PhoneNo’].’
’;
echo ‘Email: ‘.$row[‘Email’].’
’;
echo ‘Comment: ‘.$row[‘Comment’].’
’;
echo ‘


’;
}[/code]
(I have a odbc_fetch_array function that works as the mysql_fetch_array does)

So I can assume that the connection ($link), the DB and the table “contact” are fine, right?
OK.

when I try INSERT query:

$insert = "INSERT INTO contact (DateTime, FullName, PhoneNo, Email, Comment) VALUES ('$date', '$name', '$phone', '$email', '$comment')";
I get a message:

[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

I even tried with no variables, just strings:

$insert = "INSERT INTO contact ( DateTime, FullName, PhoneNo, Email, Comment ) VALUES ( '2007-08-19 15:06:08', 'person', '01010101', '[email protected]', 'hi there' )";

and came up with the same error message. Then I tried adding quotation marks in the field section:

$insert = "INSERT INTO contact ( 'DateTime', 'FullName', 'PhoneNo', 'Email', 'Comment' ) VALUES ( '2007-08-19 15:06:08', 'amitKeret', '01010101', '[email protected]', 'hi there' )";

and recieved this message:

[Microsoft][ODBC Microsoft Access Driver] The INSERT INTO statement contains the following unknown field name: ''DateTime''. Make sure you have typed the name correctly, and try the operation again.

When obviously the field name is correct, since I can extract and display the information.

so…
Does anyone have a clue?

thank you,
amit

sry io have no idea about the access-sql-syntax. As i remember fieldnames should be enclosed in sqare-brekats []

but i would sugest to do the following: try to create the statement inside access and have a look at it. Then try to use the exact same syntax (even same quoted and exact field names [contact.DateTime]).

hope this helps

Sponsor our Newsletter | Privacy Policy | Terms of Service