Danny620 Posted July 28, 2009 Share Posted July 28, 2009 when i run this code i want it to insert the future date into the db but when i run it it inserts blanks like so 1 0000-00-00 00:00:00 2 1 0000-00-00 00:00:00 2 it should insert the current date and time i have set heres the code <?php require_once ('mysqli_connect.php'); //Get HQ level. // Query the database: $q = "SELECT hqlevel FROM `construction` WHERE user_id =1 LIMIT 1"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $hqlevel = mysqli_fetch_array ($r, MYSQLI_ASSOC); //End of Hq level $hqlevel = $hqlevel['hqlevel']; //Get HQ Buildtime. // Query the database: $q = "SELECT time FROM `build_time` WHERE level = $hqlevel"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $buildtime = mysqli_fetch_array ($r, MYSQLI_ASSOC); //End HQ Buildtime. $buildtime = $buildtime['time']; $builddate = date("d/m/Y H:i", time() + (60 * $buildtime)); $userid = 1;//turn it to session when programmed login //Upgrade to the next level. if(isset($_POST['upgrade'])){ // Query the database: $q = "INSERT INTO construction( user_id, complete, hqlevel ) VALUES ($userid, '$builddate', $hqlevel)"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); //End Upgrade to next level. echo $builddate; } /* SELECT * FROM `build_time` LIMIT 0 , 30 */ ?> <form name="form1" method="post" action=""> <table width="593" height="33" border="0"> <tr> <td width="103" height="29">Headquarters</td> <td width="174"><label> <input name="upgrade" type="submit" id="upgrade" value="<?php echo "Upgrade to $hqlevel"; ?>"> </label></td> <td width="302"><?php echo "$buildtime minutes taken to construct this building."; ?></td> </tr> </table> </form> <?php $date = date("d/m/Y H:i"); echo "<b>Server time:</b> $date"; ?> Link to comment https://forums.phpfreaks.com/topic/167806-solved-php-blank-insert-mysql/ Share on other sites More sharing options...
mmarif4u Posted July 28, 2009 Share Posted July 28, 2009 echo the date b4 putting it in the query to insert/update. Link to comment https://forums.phpfreaks.com/topic/167806-solved-php-blank-insert-mysql/#findComment-885010 Share on other sites More sharing options...
Danny620 Posted July 28, 2009 Author Share Posted July 28, 2009 i have done and i get this which is what i want to inset 28/07/2009 16:59 what should i set the filed and settings to in mysql Link to comment https://forums.phpfreaks.com/topic/167806-solved-php-blank-insert-mysql/#findComment-885016 Share on other sites More sharing options...
mmarif4u Posted July 28, 2009 Share Posted July 28, 2009 $builddate = date("Y-m-d H:i:s", time() + (60 * $buildtime)); Link to comment https://forums.phpfreaks.com/topic/167806-solved-php-blank-insert-mysql/#findComment-885021 Share on other sites More sharing options...
Danny620 Posted July 28, 2009 Author Share Posted July 28, 2009 thank you so much that fixed it i am gusseing that the corrent way to store it as a date stamp Link to comment https://forums.phpfreaks.com/topic/167806-solved-php-blank-insert-mysql/#findComment-885040 Share on other sites More sharing options...
mmarif4u Posted July 28, 2009 Share Posted July 28, 2009 Lets assume that you are using data type as datetime in mysql. Mysql accept datetime in this format. 2009-07-28 12:23:76 After saving, when you are pulling it from mysql. you can change it to other formats to display. If your problem is solved, plz mark thread as solved. Link to comment https://forums.phpfreaks.com/topic/167806-solved-php-blank-insert-mysql/#findComment-885047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.