SQL and NOW()

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Rob
Forum Commoner
Posts: 33
Joined: Fri Oct 03, 2003 3:18 pm

SQL and NOW()

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try ...
$sql = "INSERT INTO news (id, postdate, title, newstext, byuser) VALUES (NULL, NOW(), '$subject', '$message', '{$_SESSION['loggedin']}'";
mysql_query($sql);
User avatar
Rob
Forum Commoner
Posts: 33
Joined: Fri Oct 03, 2003 3:18 pm

Post by Rob »

I tryed it, nothing happend...dident even insert into SQL at all.
User avatar
Rob
Forum Commoner
Posts: 33
Joined: Fri Oct 03, 2003 3:18 pm

Post 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
User avatar
Rob
Forum Commoner
Posts: 33
Joined: Fri Oct 03, 2003 3:18 pm

Post by Rob »

I got it, now() cant be 'now()'...or it trys to input the word now(). Thanks
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
murph
Forum Commoner
Posts: 29
Joined: Fri Oct 03, 2003 1:28 pm
Location: washington

Post 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 ( ) );
Post Reply