PDA

View Full Version : INSERT INTO Statement error....???[Resolved}



xman51
06-21-2005, 03:04 PM
Hello All,


I have part of a PHP page I am trying to write which i want it to write information to a database. I have the odbc system dsn created on my machine. And I was able to execute a simple "Select * From" Clause using the same source, but this sql statement i have in the code below is giving me all sorts of trouble:



<html>
<body>


<?php

$userIP=$_SERVER["REMOTE_ADDR"];
$DateStr=date("l dS of F Y h:i:s A");
$FlashVer="Flash V6";
$BrowseVer=$_SERVER["HTTP_USER_AGENT"];


$conn=odbc_connect('FlashStats','','');
if (!$conn)
{
exit("Connection Failed: " . $conn);
}
$sql="INSERT INTO [Jun 2005] (IPAddress, DateTime, Flashversion, Browserversion) " .
"VALUES ('$userIP', '$DateStr', '$FlashVer', '$BrowseVer') ";
echo $sql;
$rs=odbc_exec($conn,$sql);
if (!$rs)
{
exit("Error in SQL");
}

?>


</body>
</html>

And here is the output in the browser:


INSERT INTO [Jun 2005] (IPAddress, DateTime, Flashversion, Browserversion) VALUES ('127.0.0.1', 'Tuesday 21st of June 2005 09:57:46 AM', 'Flash V6', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)')
Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in c:\phpdev\www\test\odbc.php on line 21
Error in SQL

Does anyone know what the hell this means and how to fix it?!?!? :confused:

Thanks in advance,

Xman51

Nightfire
06-21-2005, 03:12 PM
$sql="INSERT INTO 'Jun 2005' (IPAddress, DateTime, Flashversion, Browserversion) " .
"VALUES ('$userIP', '$DateStr', '$FlashVer', '$BrowseVer')";

xman51
06-21-2005, 03:18 PM
Thanks for the quick reply...now it gives me this error:


INSERT INTO 'Jun 2005' (IPAddress, DateTime, Flashversion, Browserversion) VALUES ('127.0.0.1', 'Tuesday 21st of June 2005 10:16:50 AM', 'Flash V6', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)')
Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in query. Incomplete query clause., SQL state S1000 in SQLExecDirect in c:\phpdev\www\test\odbc.php on line 21
Error in SQL

See where it says Incomplete query clause? :confused:

Thanks again,

Xman51

xman51
06-21-2005, 06:59 PM
Here is the solution for all who is interested:


$sql="INSERT INTO Jun2005 " .
"VALUES ('$userIP', '$DateStr', '$FlashVer', '$BrowseVer', '$referer', '$Entry', '$Exit', '$Hits', '$Files', '$Pages', '$Kbytes')";

Make sure you dont have a primary key selected in the db, and that your formats are correct. (The reason it wouldn't write to the database is because the date format did not match...tee hee :o ) Also in this format you have to give a value for every field in the db. If any of them have been omitted then it will throw an error.

Thanks to all for your assistance,

Xman51