postbil.com Posted March 7, 2011 Share Posted March 7, 2011 Hello Phpfreaks.. I had a little problem by insetting a timestamp in to a MySQL table. I have two timestamps $ts1 & $ts2 but all the time I get 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 'header ="test", startTs ="1309680000", ' at line 2 Here is the code where I try to insert the timestamp. $query = 'insert user_calendar header ="' . mysql_real_escape_string($header, $db) . '", startTs ="' . mysql_real_escape_string($ts1, $db) . '", endTs ="' . mysql_real_escape_string($ts2, $db) . '", subject ="' . mysql_real_escape_string($subject, $db) . '", userCalendarID = "' . mysql_real_escape_string($site_user['userID'], $db) . '"'; mysql_query($query, $db) or die(mysql_error($db)); Here is the code where I create the table to database: $query = 'CREATE TABLE IF NOT EXISTS user_calendar ( userCalendarID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, header VARCHAR(50) NOT NULL, startTs DATETIME NOT NULL, endTs DATETIME NOT NULL, subject VARCHAR(255) NOT NULL, PRIMARY KEY(userCalendarID) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); Can someone please tell me what I do wrong!! Postbil.com Quote Link to comment https://forums.phpfreaks.com/topic/229888-timestamp-problem/ Share on other sites More sharing options...
Pikachu2000 Posted March 7, 2011 Share Posted March 7, 2011 This is a syntactical error, not a problem with the timestamp. If you echo the query, you'll see that the syntax isn't even close to what it should be for an INSERT query, which should take the form of: INSERT INTO `table` (`field1`, `field2`, `field3`, `etc` ) VALUES ( 'value1', 'value2', 'value3', 'etc') If the number of values being inserted into the table is exactly the same as the number of fields that exist in the table the field list can be omitted, but if you add a field to the table at some point in the future, you'll break any INSERT queries that are written that way. Quote Link to comment https://forums.phpfreaks.com/topic/229888-timestamp-problem/#findComment-1184059 Share on other sites More sharing options...
fenway Posted March 7, 2011 Share Posted March 7, 2011 Actually, with the word SET, it would actually work ... alternate syntax... though it's evil. Quote Link to comment https://forums.phpfreaks.com/topic/229888-timestamp-problem/#findComment-1184062 Share on other sites More sharing options...
Pikachu2000 Posted March 7, 2011 Share Posted March 7, 2011 Even without INTO? Gawd, that's a mess. Quote Link to comment https://forums.phpfreaks.com/topic/229888-timestamp-problem/#findComment-1184067 Share on other sites More sharing options...
fenway Posted March 7, 2011 Share Posted March 7, 2011 Actually, INTO has always been optional -- regardless of syntax. Quote Link to comment https://forums.phpfreaks.com/topic/229888-timestamp-problem/#findComment-1184077 Share on other sites More sharing options...
Pikachu2000 Posted March 7, 2011 Share Posted March 7, 2011 Really? Well, then I've typed too much over the years I guess. Quote Link to comment https://forums.phpfreaks.com/topic/229888-timestamp-problem/#findComment-1184079 Share on other sites More sharing options...
fenway Posted March 7, 2011 Share Posted March 7, 2011 Oh, same here -- I can't possibly do it any differently at this point. Quote Link to comment https://forums.phpfreaks.com/topic/229888-timestamp-problem/#findComment-1184080 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.