Re: [PHP-DB] Inserting date into a table

2004-04-24 Thread John W. Holmes
Pambos Nicolaou wrote:

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');
Two ways:

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


[PHP-DB] Inserting date into a table

2004-04-23 Thread Pambos Nicolaou
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');

Thanks in advance

Pambos Nicolaou

_
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Inserting date into a table

2004-04-23 Thread Rachel Rodriguez
 
 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');
 

Use the word null (no quotes) in place of 'TIMESTAMP':

INSERT INTO $table
VALUES('', '$name', null, '$question', '$email',
null);

The above will work in MySQL.  I haven't tried it in
other databases.

~R




__
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25ยข
http://photos.yahoo.com/ph/print_splash

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php