hasek522 Posted July 25, 2008 Share Posted July 25, 2008 Is this the correct way in php and sql to input the current date $sql = "INSERT INTO accounts (userid,accountid,amount,description,date) VALUES( '" . $userid . "', '" . $accountid. "', '" . $amount. "', '" . $description . "', NOW() )"; Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 25, 2008 Share Posted July 25, 2008 in php you can use time() mysql supports CURRENT_TIMESTAMP() Scott. Quote Link to comment Share on other sites More sharing options...
hasek522 Posted July 25, 2008 Author Share Posted July 25, 2008 hmm ok so now i have: $sql = "INSERT INTO transactions (userid,accountid,amount,description,date) VALUES( '" . $userid . "', '" . $accountid. "', '" . $amount. "', '" . $description . "', CURRENT_TIMESTAMP() )"; changed account to transactions (my own mistake) and did the current time stamp but am still not getting this sql statement to work. Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 25, 2008 Share Posted July 25, 2008 that looks fine to me do you have mysql_query($sql) or die(mysql_error()); on the end of your query and does it get an error Scott. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 25, 2008 Share Posted July 25, 2008 I personally use NOW() and have never used CURRENT_TIMESTAMP(). Try NOW() and show us the error (if any). Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 25, 2008 Share Posted July 25, 2008 dev.mysql.com says that CURRENT_TIMESTAMP and CURRENT_TIMESTAMP() are synonyms for NOW(). so it really doesn't matter. Scott. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 25, 2008 Share Posted July 25, 2008 But NOW() is less typing. =P Quote Link to comment Share on other sites More sharing options...
Barand Posted July 25, 2008 Share Posted July 25, 2008 I use NOW() if the field is type DATETIME and CURDATE() if the field is type DATE Quote Link to comment Share on other sites More sharing options...
hasek522 Posted July 26, 2008 Author Share Posted July 26, 2008 Ok i tried doing the mysqlerror method and nothing showed up. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 26, 2008 Share Posted July 26, 2008 So what's the actual problem? Quote Link to comment Share on other sites More sharing options...
hasek522 Posted July 26, 2008 Author Share Posted July 26, 2008 ok so now the actual problem is the SQL insert statement dosnt actually insert the data. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 26, 2008 Share Posted July 26, 2008 Do you actually call mysql_query() on the SQL string? Someone did that recently and asked for help. =P Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 26, 2008 Share Posted July 26, 2008 dude, just do $now = strtotime("now") and then insert the variable $now into the database. Does the same exact thing. Quote Link to comment Share on other sites More sharing options...
Third_Degree Posted July 26, 2008 Share Posted July 26, 2008 $sql = "INSERT INTO `transactions` ( `userid`, `accountid`, `amount`, `description`, `date` ) VALUES ( '" . $userid . "', '" . $accountid . "', '" . $amount . "', '" . $description . "', '" . date( 'Y-m-d' ) . "'" ); mysql_query( $sql ) or die( mysql_error( ) ); Try it? Quote Link to comment Share on other sites More sharing options...
hasek522 Posted July 26, 2008 Author Share Posted July 26, 2008 ok i figured things out, thanks for all the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.