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() )"; Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/ 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. Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599798 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. Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599801 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. Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599804 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). Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599807 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. Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599810 Share on other sites More sharing options...
DarkWater Posted July 25, 2008 Share Posted July 25, 2008 But NOW() is less typing. =P Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599811 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 Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599819 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. Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599850 Share on other sites More sharing options...
DarkWater Posted July 26, 2008 Share Posted July 26, 2008 So what's the actual problem? Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599853 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. Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599855 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 Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599859 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. Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599974 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? Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-599979 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 Link to comment https://forums.phpfreaks.com/topic/116656-now-with-php/#findComment-600020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.