affordit Posted January 24, 2008 Share Posted January 24, 2008 <?php $name="Patrick"; include("k_falls_dbinfo2.inc.php"); mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO test (name, time_submitted) VALUES ('$name', now())"; mysql_query($query); mysql_free_result( $result ); mysql_close(); echo "All Done."; $st = strtotime("+1 week"); $dt = new DateTime("@$st"); echo ('$dt') ?> Quote Link to comment Share on other sites More sharing options...
p2grace Posted January 25, 2008 Share Posted January 25, 2008 First of all you should always list what the problem is so we know where to look. Are the variables $username and $password set? also try updating your code to this: <?php $name="Patrick"; include("k_falls_dbinfo2.inc.php"); mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO `test` (`name`, `time_submitted`) VALUES ('$name', NOW())"; mysql_query($query); mysql_close(); echo "All Done."; $st = strtotime("+1 week"); $dt = new DateTime("@$st"); echo "$dt"; ?> Note, the query will not work if time_submitted is not set to timestamp, datetime, or date in mysql. The biggest error I saw was the echo statement was like this echo ('$dt') which the variable is never being shown because you were using single quotes, and you were missing the semi-colon at the end. The semi-colon at the end wouldn't break it unless there's more code after the echo statement. Quote Link to comment Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 It still does not echo $dt Quote Link to comment Share on other sites More sharing options...
p2grace Posted January 25, 2008 Share Posted January 25, 2008 Ah right, try this: $st = date("m/d/Y",strtotime("+1 week")); echo $st; Quote Link to comment Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 SWEEEET Thanks p2grace that got the job done. You have a great day Quote Link to comment Share on other sites More sharing options...
p2grace Posted January 25, 2008 Share Posted January 25, 2008 No problem, glad I could help Would you mind hitting the Topic Solved button, Thank you Quote Link to comment Share on other sites More sharing options...
KrisNz Posted January 25, 2008 Share Posted January 25, 2008 $dt is an object that cant be converted to a string. you probably want something like echo $dt->format("Y-m-d H:i:s"); 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.