Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-07-2008, 06:49 PM   PM User | #1
metroid
New Coder

 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
metroid is an unknown quantity at this point
Timed Registered Account

Ok, so I am trying to code something to where when people register, they can pay for a membership. They can pay for 30 days, 60 days or 90 days. (This is only an example.)

How would I be able to code it to where it will check to see if there account has expired? I have already coded the registration and log in. And there is a timestamp submitted to the MySQL db, as date(ymdHis).

So how should I do this?
metroid is offline   Reply With Quote
Old 08-07-2008, 08:03 PM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
The date time functions of mysql is all you need, check them out:
http://dev.mysql.com/doc/refman/5.0/...functions.html

Post back if you run into issues...
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 08-07-2008, 08:05 PM   PM User | #3
metroid
New Coder

 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
metroid is an unknown quantity at this point
Ok, thanks. So should I code a query into the php file to subtract the two dates?
metroid is offline   Reply With Quote
Old 08-07-2008, 08:07 PM   PM User | #4
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Yep-- look at the DATE_SUB function from the link.
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 08-07-2008, 08:46 PM   PM User | #5
metroid
New Coder

 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
metroid is an unknown quantity at this point
How do I incorporate that into a query?
metroid is offline   Reply With Quote
Old 08-07-2008, 09:06 PM   PM User | #6
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
This should push you in the right direction:
select datediff(now(), dateField) from table

Run that with your table + fields and figure out what to put into the where clause.
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 08-07-2008, 09:44 PM   PM User | #7
metroid
New Coder

 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
metroid is an unknown quantity at this point
Ok, that worked.

But now, I am having a problem. The person asking me to code this has asked to let them sign up for a 1 day free trial.

Heres the thing, when someone signs up for it, if they sign up at 11:59 PM, they only get a 1 minute free trial, instead a full 24 hours. How should I fix this?
metroid is offline   Reply With Quote
Old 08-07-2008, 09:52 PM   PM User | #8
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Try:
SELECT DATE_ADD(dateField, INTERVAL 1 DAY) FROM table
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 08-07-2008, 10:05 PM   PM User | #9
metroid
New Coder

 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
metroid is an unknown quantity at this point
PHP Code:
//Gets information about account
$get_email_data "SELECT * FROM online_videos WHERE email='$email'";
$get_email_result mysql_query($get_email_data$datacon);
$email_row mysql_fetch_assoc($get_email_result);


$account_init_time $email_row['init_time'];
$account_duration_days $email_row['account_duration_days'];

$subtract_date_query "SELECT DATE_SUB(NOW(), INTERVAL '" .$account_init_time "', DAY)";
$query_result mysql_query($subtract_date_query);
$query_row mysql_fetch_row($query_result);
echo 
mysql_error($datacon);
$account_time $query_row["0"];
echo 
$account_time;
if(
$account_time >= $account_duration_days)
{
session_destroy();
header("location:videos.php?msg=expired");

When that is executed, I get this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' DAY)' at line 1

But according to the manual, DAY is where it should be...
metroid is offline   Reply With Quote
Old 08-07-2008, 10:11 PM   PM User | #10
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
$subtract_date_query = "SELECT DATE_SUB(NOW(), INTERVAL " .$account_init_time . " DAY)";

echo out $subtract_date_query and run in mysql to debug.
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 08-07-2008, 10:21 PM   PM User | #11
metroid
New Coder

 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
metroid is an unknown quantity at this point
I entered in that code, and I got this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '23:58:56 DAY)' at line 1

I am running MySQL 6.02

Last edited by metroid; 08-07-2008 at 10:24 PM..
metroid is offline   Reply With Quote
Old 08-07-2008, 10:24 PM   PM User | #12
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Echo out the query and debug it. It looks like you are putting in the wrong variable for the interval. It should be an integer number....e.g. 1 day, 2 day you get the idea.
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 08-07-2008, 10:34 PM   PM User | #13
metroid
New Coder

 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
metroid is an unknown quantity at this point
So, it doesn't actually subtract two dates? It just adds/subtracts to them.

The db has the timestamp from when they registered, and then stores how many days they get.(In this case, 1).

How should I do this then? Is there a way to do this php side?

Last edited by metroid; 08-07-2008 at 10:53 PM..
metroid is offline   Reply With Quote
Old 08-08-2008, 12:57 AM   PM User | #14
metroid
New Coder

 
Join Date: Oct 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
metroid is an unknown quantity at this point
Sorry for the double post.

Ok, I figured it out. Instead of expressing the account_duration column in days, I express it in hours. And instead of using DATEDIFF, I use TIMEDIFF.
metroid is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:54 PM.


Advertisement
Log in to turn off these ads.