Jump to content

timestamp problem


postbil.com

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/229888-timestamp-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/229888-timestamp-problem/#findComment-1184059
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.