Okay im trying to create a script which fetches the date, adds three days, then updates this new date and time in the mysql db. I've read the php manual on time, and I'm still confused. Im useless. So far I have this: $mysql_host = "localhost"; $mysql_username = "username"; $mysql_password = "password"; $mysql_database = "database"; $id = $_REQUEST['id']; mysql_query("UPDATE db.table SET time=$thetime WHERE id='"$id"'") or die(mysql_error()); mysql_close(); PHP: I need the time/date format like this: 2010-10-04 17:45:21 Please help, thanks
Figured it out now... took me awhile but I came up with this, please advise if anyone else can think of better method. <?php $year = date("Y:m:d"); $time = date("G:i:s"); $future = date("Y:m:d", strtotime("+3 day")); print "$year $time - - $future $time "; ?> PHP:
Okay, I am having a problem with script... please help... Error: Parse error: syntax error, unexpected T_VARIABLE Im guessing in the mysql query, please help. <?php include('include/config.php'); include('include/function.php'); $future = date("Y:m:d G:i:s", strtotime("+3 day")); $mysql_host = "localhost"; $mysql_username = "user"; $mysql_password = "pass"; $mysql_database = "db"; $UID = $_REQUEST['UID']; mysql_query("UPDATE subscriber SET expired_time='"$future"' WHERE UID='"$UID"'") or die(mysql_error()); mysql_close(); ?> PHP:
Try this mysql_query("UPDATE subscriber SET expired_time='".$future."' WHERE UID='".$UID."'") or die(mysql_error());
this is correct mysql_query("UPDATE subscriber SET expired_time='$future' WHERE UID='$UID'") or die(mysql_error());
You can probably just do it a lot easier and faster by doing it directly in SQL. Have a look at the adddate function: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_adddate
How about: mysql_query("UPDATE `db`.`table` SET `time` = ADDDATE(NOW(), 3) WHERE `id` = '$id'") or die(mysql_error()); Code (markup):