Re: inserting server time into mysql

2006-05-09 Thread Dan Nelson
In the last episode (May 09), Alla-amin said:
 I am trying to capture my server time automatically using php and
 insert it in a mysql table.
 
 Can the timestamp or time data type capture this information
 automatically without having me code anything else?

You can use the 'timestamp' type to automatially insert the current
date/time when inserting or updating, or you can insert now() into a
regular 'datetime' field.

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html
http://dev.mysql.com/doc/refman/5.0/en/datetime.html
http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html

-- 
Dan Nelson
[EMAIL PROTECTED]

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: inserting server time into mysql

2006-05-09 Thread Alla-amin

Thanks for your help,

How can I capture this information from a php form into a mysql table. 
This is what I did:

1. I created the table and the user to access the database the table is in
create table staffs (
id int not null auto_increment primary key,
firstname varchar(20) not null,
lastname varchar(20) not null,
signin datetime not null
);

2. I created a php form to insert data into this table. The
form works but the datetime field isn't populated

html
head
titleStaff Detail/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
/head

body
?php
if(isset($_POST['add']))
{
include 'config.php';
include 'opendb.php';

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$signin = $_POST['signin'];

$query = INSERT INTO staffs (firstname, lastname, signin) VALUES 
('$firstname', '$lastname', '$signin');
mysql_query($query) or die('Error, insert query failed');

include 'closedb.php';
echo New staff detail added;
}
else
{
?
form method=post
table width=400 border=0 cellspacing=1 cellpadding=2
tr
td width=100First Name/td
tdinput name=firstname type=text/td
/tr
tr
td width=100Last Name/td
tdinput name=lastname type=text/td
/tr
tr
td width=100Sign-In Time/td
tdinput name=signin type=text/td
/tr
tr
tr
td width=100nbsp;/td
tdnbsp;/td
/tr
tr
td width=100nbsp;/td
tdinput name=add type=submit id=add value=Submit/td
/tr
/table
/form
?php
}
?
/body
/html

Am I doing something wrong?

You mentioned that I can insert the now() function into a regular datetime 
field, how can I do that?


In the last episode (May 09), Alla-amin said:
 I am trying to capture my server time automatically using php and
 insert it in a mysql table.
 
 Can the timestamp or time data type capture this information
 automatically without having me code anything else?

You can use the 'timestamp' type to automatially insert the current
date/time when inserting or updating, or you can insert now() into a
regular 'datetime' field.

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html
http://dev.mysql.com/doc/refman/5.0/en/datetime.html
http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html


RE: inserting server time into mysql

2006-05-09 Thread George Law
 
$query = INSERT INTO staffs (firstname, lastname, signin) VALUES
('$firstname', '$lastname', NOW());


I think if you alter the table and set a default value on signin to
NOW()

ALTER TABLE staffs  CHANGE signin signin DATETIME DEFAULT 'now()' not
null';

then you could just to :
$query = INSERT INTO staffs (firstname, lastname) VALUES ('$firstname',
'$lastname');

-Original Message-
From: Alla-amin [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 09, 2006 12:41 PM
To: mysql@lists.mysql.com
Subject: Re: inserting server time into mysql


Thanks for your help,

How can I capture this information from a php form into a mysql table. 
This is what I did:

1. I created the table and the user to access the database the table is
in
create table staffs (
id int not null auto_increment primary key,
firstname varchar(20) not null,
lastname varchar(20) not null,
signin datetime not null
);

2. I created a php form to insert data into this table. The
form works but the datetime field isn't populated

html
head
titleStaff Detail/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
/head

body
?php
if(isset($_POST['add']))
{
include 'config.php';
include 'opendb.php';

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$signin = $_POST['signin'];

$query = INSERT INTO staffs (firstname, lastname, signin) VALUES
('$firstname', '$lastname', '$signin');
mysql_query($query) or die('Error, insert query failed');

include 'closedb.php';
echo New staff detail added;
}
else
{
?
form method=post
table width=400 border=0 cellspacing=1 cellpadding=2
tr
td width=100First Name/td
tdinput name=firstname type=text/td
/tr
tr
td width=100Last Name/td
tdinput name=lastname type=text/td
/tr
tr
td width=100Sign-In Time/td
tdinput name=signin type=text/td
/tr
tr
tr
td width=100nbsp;/td
tdnbsp;/td
/tr
tr
td width=100nbsp;/td
tdinput name=add type=submit id=add value=Submit/td
/tr
/table
/form
?php
}
?
/body
/html

Am I doing something wrong?

You mentioned that I can insert the now() function into a regular
datetime field, how can I do that?


In the last episode (May 09), Alla-amin said:
 I am trying to capture my server time automatically using php and
 insert it in a mysql table.
 
 Can the timestamp or time data type capture this information
 automatically without having me code anything else?

You can use the 'timestamp' type to automatially insert the current
date/time when inserting or updating, or you can insert now() into a
regular 'datetime' field.

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html
http://dev.mysql.com/doc/refman/5.0/en/datetime.html
http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



RE: inserting server time into mysql

2006-05-09 Thread J.R. Bullington
The now() function would be used in the INSERT/UPDATE statement, not the
form field.

$query = INSERT INTO staffs (firstname, lastname, signin) VALUES
('$firstname', '$lastname', now());
mysql_query($query) or die('Error, insert query failed');

See the change to your variable $signin. Change that to now() and then
remove the form field signin.

To make your life a lot easier, you really should use the TIMESTAMP field.

ALTER TABLE staffs MODIFY `signin` `signin` timestamp default
CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP

This will ensure that you have the server's timestamp, not the client's
(timezones are a b**ch sometimes...)

J.R.

-Original Message-
From: Alla-amin [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 09, 2006 12:41 PM
To: mysql@lists.mysql.com
Subject: Re: inserting server time into mysql


Thanks for your help,

How can I capture this information from a php form into a mysql table. 
This is what I did:

1. I created the table and the user to access the database the table is in
create table staffs ( id int not null auto_increment primary key, firstname
varchar(20) not null, lastname varchar(20) not null, signin datetime not
null );

2. I created a php form to insert data into this table. The form works but
the datetime field isn't populated

html
head
titleStaff Detail/title
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
/head

body
?php
if(isset($_POST['add']))
{
include 'config.php';
include 'opendb.php';

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$signin = $_POST['signin'];

$query = INSERT INTO staffs (firstname, lastname, signin) VALUES
('$firstname', '$lastname', '$signin');
mysql_query($query) or die('Error, insert query failed');

include 'closedb.php';
echo New staff detail added;
}
else
{
?
form method=post
table width=400 border=0 cellspacing=1 cellpadding=2 tr td
width=100First Name/td tdinput name=firstname type=text/td
/tr tr td width=100Last Name/td tdinput name=lastname
type=text/td /tr tr td width=100Sign-In Time/td tdinput
name=signin type=text/td /tr tr tr td width=100nbsp;/td
tdnbsp;/td /tr tr td width=100nbsp;/td tdinput name=add
type=submit id=add value=Submit/td /tr /table /form ?php }
? /body /html

Am I doing something wrong?

You mentioned that I can insert the now() function into a regular datetime
field, how can I do that?


In the last episode (May 09), Alla-amin said:
 I am trying to capture my server time automatically using php and 
 insert it in a mysql table.
 
 Can the timestamp or time data type capture this information 
 automatically without having me code anything else?

You can use the 'timestamp' type to automatially insert the current
date/time when inserting or updating, or you can insert now() into a regular
'datetime' field.

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html
http://dev.mysql.com/doc/refman/5.0/en/datetime.html
http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html


smime.p7s
Description: S/MIME cryptographic signature


RE: inserting server time into mysql

2006-05-09 Thread Alla-amin
Thanks guys,

It worked - thank you all so very much.