close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Insert DATETIME to MySQL

Thread began 8/26/2009 9:22 am by Steve | Last modified 8/26/2009 11:07 am by Steve | 1924 views | 3 replies |

Steve

Insert DATETIME to MySQL

Hello,
I would like to make an insert to a mysql DB to a DATETIME field using the SQL now() function.

$WA_fieldNamesStr = "cname|ccompany|cphone|cemail|ccomments|cinsertdate";
$WA_fieldValuesStr = "".((isset($_POST["fld_name"]))?$_POST["fld_name"]:"") ."" . "|" . "".((isset($_POST["fld_company"]))?$_POST["fld_company"]:"") ."" . "|" . "".((isset($_POST["fld_phone"]))?$_POST["fld_phone"]:"") ."" . "|" . "".((isset($_POST["fld_email"]))?$_POST["fld_email"]:"") ."" . "|" . "".((isset($_POST["fld_comments"]))?$_POST["fld_comments"]:"") ."" . "|" . "now()";



returns an error of:

" Incorrect datetime value: 'now()' for column 'cinsertdate' at row 1 "

Why is this? Allowing SQL to set the date is the most efficient means but for some reason this is not happening.

Sign in to reply to this post

Steve

btw, I realize I can use a hidden field formatted in the expected SQL DATETIME format such as:

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

But it seems the now() sql function is more efficient and I wonder if there is something available to achieve this goal.

Sign in to reply to this post

Ray BorduinWebAssist

You don't need a hidden form element. You can set the value to:

<?php echo(date('Y-m-d H:i:s')); ?> directly in the column binding.

I don't think DW will allow you to reference mySQL functions. It doesn't pass the sql injection checks that are in place. Quotes are put around all date fields, so I just don't think the NOW() technique will work.

Sign in to reply to this post
Did this help? Tips are appreciated...

Steve

Thanks for that come back Ray.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...