Insert Statement error (with ms access db)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
funsutton
Forum Newbie
Posts: 9
Joined: Sun Jan 18, 2004 12:02 pm

Insert Statement error (with ms access db)

Post by funsutton »

I get the following error message, and I don't understand where it is coming from. Can anyone help?

Code: Select all

Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft JET Database Engine
Description: Syntax error in INSERT INTO statement.' in F:\web\websites\fia\home\logger1.php:35 
Stack trace: #0 F:\web\websites\fia\home\logger1.php(35): 
com->Execute('INSERT INTO log...') #1 {main} thrown in F:\web\websites\fia\home\logger1.php on line 35

Here is the code:

Code: Select all

<? 
$ipaddress = $_SERVER["REMOTE_ADDR"];
$url = $_SERVER["PHP_SELF"];	
if ($url == "/") {
	$url = "/index.html";
	}
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$date = (date ("F j, Y, g:i:s a"));
$nologip = array("");
$browser = $_SERVER["HTTP_USER_AGENT"];
$time = time();
$search = "search.msn.com";
$resultmsn = strpos($browser, $search);
$searchgoogle = "bot";
$resultgoogle = strpos($browser, $searchgoogle);
$searchyahoo = "Yahoo! Slurp";
$resultyahoo = strpos($browser, $searchyahoo);
$searcharchiver = "archiver";
$resultarchiver = strpos($browser, $searcharchiver);
$searchcrawler = "crawler";
$resultcrawler = strpos($browser, $searchcrawler);
$searchjeeves = "Jeeves";
$resultjeeves = strpos($browser, $searchjeeves);

  if ((in_array($ipaddress, $nologip)) OR ($resultmsn !== false) OR ($resultgoogle !== false) OR ($resultyahoo !== false) OR ($resultarchiver !== false) OR ($resultcrawler !== false) OR ($resultjeeves !== false))  {
  		echo "";
	}
$db = 'f:\web\databases\fia\log.mdb';
$conn = new COM ("ADODB.Connection") or die( "Cannot start ADO" ); 
$conn->Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".$db );
$sql = "INSERT INTO log (Hostname,Page,Date,Browser,Referer,Timestamp) VALUES('$hostname','$url','$date','$browser','$referer','$time')";
$rs = $conn->Execute( $sql );
$conn->Close(); //Close database connection 
$conn->Release(); //Release resources for this connection 
?>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Output $sql before it's executed and I'll bet it won't look exactly like you think it should.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply