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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.