MySQL basic date/time question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mc3
Forum Newbie
Posts: 13
Joined: Thu Jan 24, 2008 5:31 pm

MySQL basic date/time question

Post by mc3 »

Hi there.

I'm trying to create a site which connects to a table of users and their associated timestamps (which begin with default values of 0000-00-00). I want the site to check the timestamp of the user, and then determine whether or not the timestamp is more than three days old. If it is, the operation should die and if it's not or is equal to the default value, the user should be able to proceed.


(I'm working on allowing a download for a three-day window which begins the first time the user logs in.)



Here's what I've got so far. I'm getting the following error with my $setcutoffdate variable:
Catchable fatal error: Object of class stdClass could not be converted to string in...

Code: Select all

 
$user = $_POST["user"];
$pw = $_POST["pw"];
$email = $_POST["email"];
 
 
 
 
//check username
 
$checkusername = mysql_query("SELECT user FROM mydb WHERE user = '$user'");
 
$numuserrows=mysql_num_rows($checkusername);
 
if ($numuserrows==0)
    {
    echo "Sorry, we can't find that username. Be sure you typed it correctly.";
    die;
        }
 
 
//check password
 
$checkpassword = mysql_query("SELECT pw FROM mydb WHERE user = '$user'");
 
$checkpasswordresult = mysql_fetch_object($checkpassword);
 
if ($pw != $checkpasswordresult->pw)
    {
    echo "Password wrong.";
    die;
    }
 
//echo '<pre>'.print_r($checkpasswordresult).'</pre>';
 
 
//get activatetime
 
$activatetime = mysql_query("SELECT activatetime FROM mydb  WHERE user = '$user'");
 
$checkactivatetime = mysql_fetch_object($activatetime);
 
echo '<pre>'.print_r($checkactivatetime).'</pre>';
 
 
//get current date
$currentdate = mysql_query("SELECT CURDATE()");
 
$checkcurrentdate = mysql_fetch_object($currentdate);
 
echo '<pre>'.print_r($checkcurrentdate).'</pre>';
 
 
//set cutoff date
$setcutoffdate = "DATE_SUB('$checkcurrentdate',INTERVAL 3 DAY)";
 
$checksetcutoffdate = mysql_fetch_object($setcutoffdate);
 
echo '<pre>'.print_r($checksetcutoffdate).'</pre>';
 
 
 
//check if activatetime is before cutoff
 
if($checkactivatetime < $checksetcutoffdate)
    echo "Sorry, this username was activated more than 3 days ago and can not be used to download anymore.";
 
elseif($checkactivatetime == 0000-00-00)
    //update activatetime on database
    mysql_query("UPDATE seens_dl SET activatetime = SYSDATE() WHERE user = = '$user'");
 
else
    {
// 1. send email
 
    $headers="From: $email";
    $to="email@gmail.com";
    $subject="download";
    $message="I used the username $user to download. My e-mail address is $email";
//  mail($to,$subject,$message,$headers);
 
 
//and 2. send user to download page
 
 
Last edited by mc3 on Fri Jan 25, 2008 8:29 am, edited 4 times in total.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: MySQL basic date/time question

Post by aceconcepts »

Post the error you get

Also, take a look at: http://uk2.php.net/strtotime
mc3
Forum Newbie
Posts: 13
Joined: Thu Jan 24, 2008 5:31 pm

Re: MySQL basic date/time question

Post by mc3 »

Nobody? Help would be much appreciated.... :banghead:
Post Reply