Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Rob
Forum Commoner
Posts: 33 Joined: Fri Oct 03, 2003 3:18 pm
Post
by Rob » Thu Oct 16, 2003 8:01 pm
$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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Oct 16, 2003 8:06 pm
Try ...
$sql = "INSERT INTO news (id, postdate, title, newstext, byuser) VALUES (NULL, NOW(), '$subject', '$message', '{$_SESSION['loggedin']}'";
mysql_query($sql);
Rob
Forum Commoner
Posts: 33 Joined: Fri Oct 03, 2003 3:18 pm
Post
by Rob » Thu Oct 16, 2003 8:10 pm
I tryed it, nothing happend...dident even insert into SQL at all.
Rob
Forum Commoner
Posts: 33 Joined: Fri Oct 03, 2003 3:18 pm
Post
by Rob » Thu Oct 16, 2003 8:27 pm
$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
Rob
Forum Commoner
Posts: 33 Joined: Fri Oct 03, 2003 3:18 pm
Post
by Rob » Thu Oct 16, 2003 8:33 pm
I got it, now() cant be 'now()'...or it trys to input the word now(). Thanks
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Thu Oct 16, 2003 8:35 pm
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 » Fri Oct 17, 2003 2:04 am
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 ( ) );