Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Help please !! Need to insert date automatically in form

Guest
Jan 22, 2007 Jan 22, 2007
I have been trying unsuccessfully for a week to automatically capture today's date on a form. I can display a date on screen but it will not insert date into mySQL db. All other information is inserted as expected.
Am I just whistling in dark? Is there no way to eliminate user input for the order date field?
I have looked throughout the forums and no luck.
Anyone have any ideas about how to do?
Thanks,
Dale 🙂
TOPICS
Server side applications
465
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 22, 2007 Jan 22, 2007
In the database itself, you can have it automatically do this. I'm not
very familiar with mySQL but in MS SQL, you just do (getdate()) in the
default field. I would suspect that mySQL is similar.

Dale60 wrote:
> I have been trying unsuccessfully for a week to automatically capture today's
> date on a form. I can display a date on screen but it will not insert date into
> mySQL db. All other information is inserted as expected.
> Am I just whistling in dark? Is there no way to eliminate user input for the
> order date field?
> I have looked throughout the forums and no luck.
> Anyone have any ideas about how to do?
> Thanks,
> Dale :-)
>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 22, 2007 Jan 22, 2007
Dale60 wrote:

> I have been trying unsuccessfully for a week to automatically capture today's
> date on a form. I can display a date on screen but it will not insert date into
> mySQL db. All other information is inserted as expected.
> Am I just whistling in dark? Is there no way to eliminate user input for the
> order date field?
> I have looked throughout the forums and no luck.
> Anyone have any ideas about how to do?


INSERT INTO TABLE (col1,col2,... yourdatecolumn)
VALUES ("foo","bar",... NOW())
Mick

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 23, 2007 Jan 23, 2007
Thanks to you both for your replies. My server was down so could not get on these until now. I have tried both but neither works. Here is my code snippet from with Dreamweaver. Maybe this will help provide answwer. I tried both NOW() and CURTIME(). In my database the $order_date is a DATE field.:
$insertSQL = sprintf("INSERT INTO `Order_Master(email, acct_no, order_date, item_id, Qty, UM, TransType, comments, when_done) VALUES ('$email', '$acct_no', CURTIME(), '$item_id', '$Qty', '$UM', '$TransType', '$comments', NOW())");
Let me know what you think. I've tried so many approaches my fingers are wearing out.!! Thanks,
Dale:
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2007 Jan 24, 2007
With setting a default value, in MS SQL, I have to tell it not to accept
nulls to force it to set the default.

Again, not all that familiar with mysql. I can look it up at home to see.

http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html

This may help...not sure because it's been about a year since I've done
anything with mysql

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 30, 2007 Jan 30, 2007
You can use a timestamp function within your MySQL table, but remember you can only use the timestamp function ONCE in a table.

Using the timestamp Function:
Set the field type to TIMESTAMP. You can also set the default to CURRENT_TIMESTAMP and the attributes to ON UPDATE CURRENT_TIMESTAMP if you want the timestamp to change when the record is updated.

If you want to record times more than the one time you are using the timestamp and you are using PHP/MySQL or PHP/MySQL ADODB (InterAKT's PhAKT Extension), then try this:

http://chuckomalley.net/help/insert_date_help.php

That gets the time into the MySQL Database. Next thing you'll want to do is to have it display the time the way you want it. The default will display it as yyyy-mm-dd hh:mm:ss and you may not want it that way. To display it the way you want it try this:

http://chuckomalley.net/help/display_formatted_date.php

For the specific syntax on using this, refer to the online MySQL Manual and search for DATE_FORMAT() at http://dev.mysql.com/doc/mysql/en/index.html

Cheers

Chuck
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 31, 2007 Jan 31, 2007
LATEST
I use PHP and dates in MySQL are a real pain!

I also have simlar issues and have found that you can use the MyPHPAdmin to set one (one only) field to timestamp and automatically change to Now() when updated (as discussed above)

But I wanted another field to keep the original create date - similar to your order date.

This is what I did.

Changed the format of the column to datetime

Created a hidden field within my form

<input name="WHATEVER" type="hidden" id="WHATEVER" value="<?php echo date("Y-m-d H:i:s"); ?>">

This automatically generates the equivalent of a Now() statement.

Then just include it as a date value in your update or insert statement

GetSQLValueString($HTTP_POST_VARS['CREATED'], "date")
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines