I have created the table below:
CREATE TABLE questions (ID INT NOT NULL AUTO_INCREMENT,name VARCHAR(30),day TIMESTAMP, question TEXT, email VARCHAR(30),answer TEXT, PRIMARY KEY(ID));
I want to insert into the TIMESTAMP field the date automatically. How can I do it using the insert command
"INSERT INTO $table VALUES('','$name','TIMESTAMP','$question','$email','NULL')";
1: INSERT INTO $table (name, question, email) VALUES ('$name','$question','$email')
This way, the ID and TIMESTAMP columns will be populated automatically. The ID column will get the next available number and the "day" column will be assigned the current date/time. Note how you can leave out the "answer" column, too, since you weren't assigning a value to it, anyhow. It will be given the default value of the column, which in this case is NULL.
2: INSERT INTO $table (name, day, question, email) VALUES ('$name',NULL,'$question','$email')
Setting the TIMESTAMP column to NULL will cause it to be set to the current date/time. This works for the first TIMESTAMP column in a table (since you only have one, it doesn't matter).
I recommend method 1.
-- ---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php