affordit Posted January 25, 2008 Share Posted January 25, 2008 I am doing something wrong here but I caan't see it can someone help? The code below is not inserting for some reason. Was working OK till I included $ds? <?php $name="Patrick"; $st = date("m/d/Y",strtotime("+30 days")); $ds = date("m/d/Y",strtotime("")); 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`, 'expire_date','date_submitted') VALUES ('$name','$st','$ds')"; mysql_query($query); mysql_close(); echo "All Done. <br> Your Subscription will expire: "; echo $st; echo $ds; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/ Share on other sites More sharing options...
revraz Posted January 25, 2008 Share Posted January 25, 2008 mysql_query($query) or die (mysql_error()); What is the field type for your date_submitted column in your DB? What purpose does strtotime serve here $ds = date("m/d/Y",strtotime("")); Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448858 Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 STARTED WITH THIS: $query = "INSERT INTO `test` (`name`, 'expire_date','date_submitted') VALUES ('$name','$st',NOW())"; COULD NOT GET IT TO INSERT SO TRIED THIS: $query = "INSERT INTO `test` (`name`, 'expire_date','date_submitted') VALUES ('$name','$st','$ds')"; ALONG WITH THIS LINE: $ds = date("m/d/Y",strtotime("")); Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448863 Share on other sites More sharing options...
revraz Posted January 25, 2008 Share Posted January 25, 2008 And what is the error when you add the part I entered above. What is the field type for your date_submitted column in your DB? Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448864 Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''expire_date','date_submitted') VALUES ('Patrick','02/24/2008',' Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448865 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 Try this: (you have single quotes around the field names when you need back ticks) <?php $name="Patrick"; $st = date("m/d/Y",strtotime("+30 days")); $ds = date("m/d/Y"); 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`,`expire_date`,`date_submitted`) VALUES ('$name','$st','$ds')"; mysql_query($query) or die("Query failed"); mysql_close(); echo "All Done. Your Subscription will expire: "; echo $st; echo $ds; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448866 Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 OK that got it to insert but 000 values in the expire_date and date_submitted fields? Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448869 Share on other sites More sharing options...
revraz Posted January 25, 2008 Share Posted January 25, 2008 Sounds right, echo $st and $ds to see what they contain. Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448872 Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 They are being echoed and they show properly but when I fetch them back with a select query they both come back as 0000-00-00 00:00:00 Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448875 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 try: <?php $st = date("Y-m-d",strtotime("+30 days")); $ds = date("Y-m-d"); ?> And...you still haven't told us the data type you have set in your table for the two fields Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448877 Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 sORRY ABOUT THAT Both are set to DATETIME Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448878 Share on other sites More sharing options...
revraz Posted January 25, 2008 Share Posted January 25, 2008 Then you need to INSERT based on the DATETIME format, as Rhodesa just did above. sORRY ABOUT THAT Both are set to DATETIME Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448881 Share on other sites More sharing options...
affordit Posted January 25, 2008 Author Share Posted January 25, 2008 DOH Thanks all got it appreciate the help guys Quote Link to comment https://forums.phpfreaks.com/topic/87756-solved-insert-problems/#findComment-448883 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.