Page 1 of 1

Update DateTime

Posted: Mon Nov 29, 2004 5:21 pm
by AliasBDI
I have a form with a hidden tag. I wanted it to grab the server time and put it in the value. Here is my hidden tag code:

Code: Select all

<input name="articles_date" type="hidden" id="articles_date" value="<?php echo datetime(); ?>">

Posted: Mon Nov 29, 2004 5:27 pm
by kettle_drum
Try the date() function instead.

I Got an Error

Posted: Tue Nov 30, 2004 8:11 am
by AliasBDI
I got an error of "Wrong parameter count for date()". I'm on a Windows Server if that helps. But the latest version of PHP is installed.

Here is my code:

Code: Select all

<?php echo date(); ?>

Posted: Tue Nov 30, 2004 8:44 am
by kettle_drum
Yeah you need to pass it the format for how you want the date:

Code: Select all

echo date("H:i d M Y");
etc. Check the manual page for more info on the format.

Okay

Posted: Tue Nov 30, 2004 10:33 am
by AliasBDI
I need in the MySQL datetime formatt. I think it is a set of 12 numbers. How would that look?

Posted: Tue Nov 30, 2004 1:44 pm
by Maugrim_The_Reaper
Use timestamp - time() - then convert on the other side to whatever format/type you wish.

Posted: Tue Nov 30, 2004 2:07 pm
by timvw
why don't you insert now() or NULL into the database instead of a variable generated by php?

here

Posted: Wed Dec 01, 2004 2:27 pm
by AliasBDI
I tried now() but it did not work. here is my code:

Code: Select all

<?php
$updateSQL = sprintf("UPDATE con_articles SET title=%s, author=%s, img_th=IFNULL(%s,img_th), img=IFNULL(%s,img), teaser=%s, common=%s, topic_id=%s, content=%s, articles_date = now(), active=%s, search1=%s, search2=%s, search3=%s WHERE id=%s",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['author'], "text"),
                       GetSQLValueString($_POST['img_th'], "text"),
                       GetSQLValueString($_POST['img'], "text"),
                       GetSQLValueString($_POST['teaser'], "text"),
                       GetSQLValueString($_POST['common'], "text"),
                       GetSQLValueString($_POST['topic_id'], "text"),
                       GetSQLValueString($_POST['content'], "text"),
                       GetSQLValueString($_POST['articles_date'], "date"),
                       GetSQLValueString(isset($_POST['active']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['search1'], "text"),
                       GetSQLValueString($_POST['search2'], "text"),
                       GetSQLValueString($_POST['search3'], "text"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_econtrol_truth411com, $econtrol_truth411com);
?>

Posted: Wed Dec 01, 2004 7:16 pm
by timvw
varchar (and the like types) values have to be between quotes, thus:

Code: Select all

foo='bar'


instead of the foo=bar you are doing now.

Posted: Wed Dec 08, 2004 5:26 am
by cookie
patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Please try the following:

Change line 2 to:

Code: Select all

$updateSQL = sprintf("UPDATE con_articles SET title=%s, author=%s, img_th=IFNULL(%s,img_th), img=IFNULL(%s,img), teaser=%s, common=%s, topic_id=%s, content=%s, articles_date=%s, active=%s, search1=%s, search2=%s, search3=%s WHERE id=%s",

Change line 11 to:
GetSQLValueString(isset($_POST['articles_date']) ? "true" : "", "defined","NOW()","0"),
:) :)
patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]