Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Syntax Error

Status
Not open for further replies.

streetbmx

Programmer
Dec 6, 2001
16
0
0
US
I am using the ODBC functions in PHP. I am trying to insert data into an Access database and I am recieving this error message:

Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in O:\Hosted Web Sites\brandon.sungur\brandonstyle_com\profile\sign.php on line 15

here is what my script looks like:

if (isset($submit)){
$ip = $_SERVER['REMOTE_ADDR'];
$date = date('h:ia m/d/y');
$connect = odbc_connect('database, 'user', 'pass');
$query = "INSERT INTO guestbook (id, date, name, message, ip) VALUES ('NULL', '$date', '$sn', '$message', '$ip')";
odbc_exec($connect, $query); # This is line 15
odbc_close($connect);
}

I can not figure out what the syntax error is, anyone have any ideas to solve this problem?
 
You are missing a quote in statement $connect=odbc_connect('database need another quote here,.....
 
Man, it sure is nice to have people around to find syntax errors for others. That's great. I can't tell you how many times I've sat in front of my computer for hours on end, cursing while trying to figure out why I'm getting a syntax error, only to find I forgot to close quote or something.
 
Actually, that is not the syntax error. I accidently deleted the single quote when taking out my real database dsn, user, and pass.
 
what is Id used for ?? you want to insert a null value in it. if it's the autoincrement key you don't have to mention it in your insert statement. Further on it's always neat to avoid null values since there are a few possibilites how the null value can be interpreted

and perhaps your date syntax has an error
i use this one. (hourdiff is used to compensate for the server time which is wrong according to gmt standard)

$hourdiff = "2";
$timeadjust = ($hourdiff * 60 * 60);
$datum = gmdate("Y-m-d G:i:s",time() + $timeadjust);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top