PDA

View Full Version : strtotime problem


seopdx
08-11-2006, 04:33 PM
Hello everyone! First time poster long time lurker. Attempting to have a script check to see if someone registered their account over 30 days ago and to change the status of their account if they did. Upon registration a timestamp is done to their client account that translates to look like July 10, 2006, 10:29 am . I run my script to check them, I get no errors and the script won't update any records that are over 30 days old either. Here it is


include "includes/config.php";
$timestamp = "SELECT tstamp FROM tblnewaccount";
$result = mysql_query($timestamp) or die ("Query failed");
if (strtotime("+30 days", $timestamp) > date('U')) {

//update the user account if they have gone past 30 days
$q = "UPDATE tblnewaccount SET status = 'Inactive'";
}
//query the table for expired peeps
$query = "SELECT * FROM tblnewaccount WHERE status = 'Inactive'";
$testout = mysql_query($query) or die ("Query failed");
while($row = mysql_fetch_array($testout)) {

//assign rows from the table to variables
$name = $row['name'];
$pass = $row['pass'];
$email = $row['mailaddy'];
$guide = $row['guide'];
$stamp = $row['tstamp'];
$gno = $row['guidenumber'];

//kick out the email to tell them to get their act together and pay for another months access
$to = "$email";
$headers = 'From: Me' . "\r\n" .
'Reply-To: me@mysite.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$content = "Dear $name,\r\n\n";
$content .= "This is an automated reminder to inform you that your access to $guide, purchased on $stamp has expired. To reactivate your monthly access, please visit http://www.mysite.com/activate.php?ig=\r\n\n";
$content .= "IMPORTANT INFORMATION\r\n";
$content .= "Some text \r\n\n";
mail($to, "Howdy", $content, $headers);

}

devinemke
08-11-2006, 07:39 PM
it looks like you are storing your dates as regular strings. don't. you really need to read up on mySQL's native Date and Time Types (http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html). by using these types you can (and should) do all of these date/time calculations within your query (not with PHP).