Page 1 of 1

SQL and NOW()

Posted: Thu Oct 16, 2003 8:01 pm
by Rob
$result= MYSQL_QUERY("INSERT INTO news (id, postdate, title, newstext, byuser)". "VALUES ('NULL', ' NOW( ) ', '$subject', '$message', '$_SESSION[loggedin]')");

The NOW() in that query just shows up as 00000000000000, what should I do to make it show up like it should, I get something like 20031016205717 when I do it with PHPMyAdmin but hows it done thru PHP in a query

and the postdate thing is timestamp(14), it says date because its how I was doing it when I started..but then I realized posts from same day wouldent be done in the right order

Posted: Thu Oct 16, 2003 8:06 pm
by markl999
Try ...
$sql = "INSERT INTO news (id, postdate, title, newstext, byuser) VALUES (NULL, NOW(), '$subject', '$message', '{$_SESSION['loggedin']}'";
mysql_query($sql);

Posted: Thu Oct 16, 2003 8:10 pm
by Rob
I tryed it, nothing happend...dident even insert into SQL at all.

Posted: Thu Oct 16, 2003 8:27 pm
by Rob
$sql = "INSERT INTO news (id, postdate, title, newstext, byuser)". "VALUES ('NULL', 'NOW()', '$subject', '$message', '$_SESSION[loggedin]')";
mysql_query($sql);

will post, but the same thing with NOW happens

Posted: Thu Oct 16, 2003 8:33 pm
by Rob
I got it, now() cant be 'now()'...or it trys to input the word now(). Thanks

Posted: Thu Oct 16, 2003 8:35 pm
by markl999
Sorry, i had a typo in my previous example..should have been..

$sql = "INSERT INTO news (id, postdate, title, newstext, byuser) VALUES (NULL, NOW(), '$subject', '$message', '{$_SESSION['loggedin']}')";
mysql_query($sql);

This works for me .. only i used a 1 instead of NULL for my local test.

Posted: Fri Oct 17, 2003 2:04 am
by murph
set it up as a variable if you need $now = NOW(); then insert it to the db like (NULL, '$now','$blah') or die ( mysql_error ( ) );