andrew_ww Posted May 23, 2007 Share Posted May 23, 2007 Hello, the following code is producing this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '', ipaddress='1.1.1.1'' at line 1 <?php // Get MySQL connection require_once('required/connection.php'); $dateTimePageOpened = date("Y-m-d H:i"); $pageOpened = $_SERVER['REQUEST_URI']; $ipaddress = $_SERVER['REMOTE_ADDR']; $sessionvar = $_SESSION['auth']; $sql = "INSERT INTO tbl_log SET"; $sql .= " dateTimeOpened='$dateTimepageOpened"; $sql .= ", page='$pageOpened'"; $sql .= ", ipaddress='$ipaddress'"; $sql .= ", sessionvar='$sessionvar'"; mysql_query($sql); $Result = mysql_query($sql, $DII) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52642-error-with-insert-statement/ Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 For starters, remove this line... mysql_query($sql); You dont want to execute the query twice. Next... what is the output of... $Result = mysql_query($sql, $DII) or die($sql."<br />". mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/52642-error-with-insert-statement/#findComment-259838 Share on other sites More sharing options...
kathas Posted May 23, 2007 Share Posted May 23, 2007 you have forgotten a single quote in your query <?php $sql .= " dateTimeOpened='$dateTimepageOpened'";// while it was $sql .= " dateTimeOpened='$dateTimepageOpened"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52642-error-with-insert-statement/#findComment-259842 Share on other sites More sharing options...
andrew_ww Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks the missing single quote has fixed it (nearly...) While the code is sending information to the database, the datetime field is being updated as this : 0000-00-00 00:00:00 Any suggestions as to why the true time / date is not being updated. thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/52642-error-with-insert-statement/#findComment-259855 Share on other sites More sharing options...
AndyB Posted May 23, 2007 Share Posted May 23, 2007 Any suggestions as to why the true time / date is not being updated. Yep. You define $dateTimePageOpened and then put $dateTimepageOpened in the query. Quote Link to comment https://forums.phpfreaks.com/topic/52642-error-with-insert-statement/#findComment-259858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.