doomdude Posted August 14, 2011 Share Posted August 14, 2011 Hey guys. I'm trying to add the date and time to a field in my database when someone presses a button. At current I've got: Button: <form action="includes/zero3.php" method="post"> <input type="hidden" name="id" value="' . $row['id'] . '" /> <input type="hidden" name="date" value="' . $row['id'] . '" /> <input type="submit" value="3 Day" class="button"></form> </form> zero3.php: <?php include("config.php"); $id = mysql_real_escape_string($_POST['id']); if (isset($_POST['id'])) { $query=("UPDATE $dbdata SET pin='1' WHERE id='$id'"); mysql_query($query); $querytwo=("UPDATE $dbdata SET date='CURDATE()' WHERE id='$id'"); mysql_query($querytwo); header("Location: /admin/accountnopin.php"); } else { header("Location: /admin/accountnopin.php"); } ?> Am I at all on the right tracks? I'll be looking to make it current date and time + 3 days after I've got the date working :S Anyone got any advice? Quote Link to comment https://forums.phpfreaks.com/topic/244741-php-mysql-datetime-insert/ Share on other sites More sharing options...
voip03 Posted August 14, 2011 Share Posted August 14, 2011 you can query 1&2 together. $query=("UPDATE $dbdata SET pin='1',date=NOW() WHERE id='$id'"); mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/244741-php-mysql-datetime-insert/#findComment-1257060 Share on other sites More sharing options...
doomdude Posted August 14, 2011 Author Share Posted August 14, 2011 Oh wow. Cool. So now that works,. Would I need to create a variable like. $3day = Now() + 3 To make it the date and time button is pressed plus 3 days? Or would it be more complex :S Quote Link to comment https://forums.phpfreaks.com/topic/244741-php-mysql-datetime-insert/#findComment-1257096 Share on other sites More sharing options...
voip03 Posted August 14, 2011 Share Posted August 14, 2011 date('l d M Y', strtotime($start. '+3 day')); Quote Link to comment https://forums.phpfreaks.com/topic/244741-php-mysql-datetime-insert/#findComment-1257103 Share on other sites More sharing options...
doomdude Posted August 14, 2011 Author Share Posted August 14, 2011 <?php include("config.php"); $day3 = date('l d M Y', strtotime($start. '+3 day')); $id = mysql_real_escape_string($_POST['id']); if (isset($_POST['id'])) { $query=("UPDATE $dbdata SET pin='1',date='$day3' WHERE id='$id'"); mysql_query($query); header("Location: /admin/accountnopin.php"); } else { header("Location: /admin/accountnopin.php"); } ?> Just makes the datetime to : 0000-00-00 00:00:00 Do I need to define $start as a date? Quote Link to comment https://forums.phpfreaks.com/topic/244741-php-mysql-datetime-insert/#findComment-1257109 Share on other sites More sharing options...
void Posted August 14, 2011 Share Posted August 14, 2011 should probably be like that: $day3 = date('Y-m-d H:i:s', strtotime('+3 day', time())); Quote Link to comment https://forums.phpfreaks.com/topic/244741-php-mysql-datetime-insert/#findComment-1257113 Share on other sites More sharing options...
doomdude Posted August 14, 2011 Author Share Posted August 14, 2011 Ahh! Of course, your my hero! Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/244741-php-mysql-datetime-insert/#findComment-1257121 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.