Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

The time is ticking

Codes here !

Moderators: macek, egami, gesf

The time is ticking

Postby icu90ucme » Mon Jul 07, 2003 2:36 pm

Problem: I only want a member's subsciption to last one year.

Solution: I need a script that will check a user's "registration date" in a mysql database and tell me a couple of month's before the year is over so i can inform the user to resubscribe.
icu90ucme
New php-forum User
New php-forum User
 
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Postby Joel » Mon Jul 07, 2003 11:08 pm

First you need to have a unix timestamp of when the user signed up. in your SQL for adding users hav UNIX_TIME()
Code: Select all
//Login Page

//Connect to db and select db

$username = $_POST["username"];
$sql = mysql_query("SELECT * FROM usertable WHERE username = '$username'");
$userinfo = mysql_fetch_array($sql);
if ($userinfo["jointime"] < ($userinfo["jointime"] + 31536000) {
       //Login
else {
       //Message for outdated subscription
}


31536000 is the number of seconds in a year, UNIX_TIME() gives a timestamp which is the number of seconds since the Unix Epoch (1 Jan 1970 from memory). If it doesn't work straight away, tell me and I shall put more thought to it.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby icu90ucme » Tue Jul 08, 2003 8:49 pm

thanks for the help... i tried out the scipt and when i went to test it out, i replaced the year in seconds "31536000" with "10" seconds... and it didn't give me my error prompt saying "your subscription is expired, please renew"... i don't understand...

$sql = mysql_query("SELECT * FROM usertable WHERE username = '$username'");
$userinfo = mysql_fetch_array($sql);
if ($userinfo["jointime"] < ($userinfo["jointime"] + 10)
{
$HTTP_SESSION_VARS['valid_user'] = $username;
echo 'your logged in as user.';
else {
//Message for outdated subscription
echo 'your subscription is expired, please renew.';
}

the "jointime" in my mysql database is put there by the command

$timestamp= mktime();

and then i insert $timestamp into the "jointime"
icu90ucme
New php-forum User
New php-forum User
 
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Postby icu90ucme » Tue Jul 08, 2003 9:34 pm

i figured it out thanks.... this is the correct script

$time= time();
$sql=mysql_query("SELECT * FROM users WHERE username='$username'");

$userinfo = mysql_fetch_array($sql);

if (($userinfo["lastmodified"] + 31536000) > ($time))
{
$HTTP_SESSION_VARS['valid_user'] = $username;
}
else
{
// Message for outdate subscription
echo 'Your subscription has expired.';
}
icu90ucme
New php-forum User
New php-forum User
 
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Postby Joel » Tue Jul 08, 2003 10:18 pm

Oh yeah, of course. Silly Me. Its supposed to be comparing now to their date plus a year.

Good to see it working.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.