Forums

PHP

This topic is locked

todays date into MySQL

Posted 10 Sep 2006 22:11:42
1
has voted
10 Sep 2006 22:11:42 dennis brownlie posted:
How do you insert a date into a MySQL table. i have a table 'inorder' which includes 3 fields; order_id, Admin_id, and order_date. the field is a 'date' field( I have also tried as datetime). the following code successfully generates a new record and inserts it into the table, however, the order_date field is always 0! When I echo $today, the correct date is displayed in the MySQL acceptable format of 2006-09-10. what am I doing wrong or what MySQL PHP concept am I missng?





<?php

// set your infomation.
$dbhost=mydbhost.com';
$dbusername='nyusername';
$dbuserpass='mypasswordr';
$dbname='myname';
<?php
// connect to the mysql database server.
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
echo "success in database connection.";

if (!mysql_select_db($dbname)) die(mysql_error());
echo "success in database selection.";
$today = date("Y-m-d";
mysql_query("INSERT INTO inorder(order_id,admin_id,order_date) values (null,'1',$today)";
echo $today;

?>

Replies

Replied 11 Sep 2006 10:56:07
11 Sep 2006 10:56:07 Patrick Woldberg replied:
try:

<pre id=code><font face=courier size=2 id=code>mysql_query("INSERT INTO inorder(order_id,admin_id,order_date) values (null,'1',NOW())";</font id=code></pre id=code>

or:

<pre id=code><font face=courier size=2 id=code>$today = time();
mysql_query("INSERT INTO inorder(order_id,admin_id,order_date) values (null,'1',FROM_UNIXTIME($today))";</font id=code></pre id=code>

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Administrator at DMXzone.com, FLzone.net, FWzone.net and DNzone.com
--------------------------------------------------

Reply to this topic