phpbeginner Posted September 25, 2009 Share Posted September 25, 2009 I have a website with subscribers which contains basic personal info, plus status. The status is based on a value for expired, free, or paid. I am trying to update a DATE field (enddate) and status field on returning to a specific page on the website after paying. Several scenarios take place as they need a free membership in order to pay. First scenario, if date field is 0000-00-00, update subscribers status and get current date, interval + 1 year. Second, if date field is < current date, again update status and get current date, interval + 1 year. Thirdly, if they pay before the enddate, enddate > current date, then enddate, interval + 1 year. Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/175489-subscription-auto-update-year/ Share on other sites More sharing options...
phpbeginner Posted September 25, 2009 Author Share Posted September 25, 2009 Trying to do this using sql but does not seem to work.....anyone have any ideas? <?php $rs=mysql_query("select * from subscribers where uniqueid=\"" . $userId . "\""); $sql = mysql_query("IF enddate < CURDATE() THEN UPDATE subscribers set status='1', enddate='CURDATE()' WHERE uniqueid=\"" . $userId . "\""); $sql2 = mysql_query("IF enddate = \"NULL\" THEN UPDATE subscribers set status='1', enddate='CURDATE()' WHERE uniqueid=\"" . $userId . "\""); $sql3 = mysql_query("IF enddate > CURDATE() THEN UPDATE subscribers set status='1', enddate= endate, INTERVAL + 1 YEAR WHERE uniqueid=\"" . $userId . "\""); ?> Link to comment https://forums.phpfreaks.com/topic/175489-subscription-auto-update-year/#findComment-924998 Share on other sites More sharing options...
eatfishy Posted September 25, 2009 Share Posted September 25, 2009 If that's all the PHP code you have to run queries in MySQL, it will not work. I don't see any connection setup in there (the server name, database name?) Also, you could create 1 query (lil more complicated) or 3 separate queries (easier to read) to do the update. Below is an example of 3 separate queries: Update Subscribers Set status='1',uniquieid='id',enddate='CURDATE()' WHERE enddate<CURDATE() Update Subscribers Set status='1',uniquieid='id',enddate='CURDATE()' WHERE enddate IS NULL Update Subscribers Set status='1',uniquieid='id',enddate=endate, INTERVAL + 1 YEAR WHERE enddate>CURDATE() I don't have access to MYsql currently, but it should be something like that above. Also, the date calculation doesn't look right to me (enddate=endate, INTERVAL + 1 YEAR)? Link to comment https://forums.phpfreaks.com/topic/175489-subscription-auto-update-year/#findComment-925039 Share on other sites More sharing options...
phpbeginner Posted September 25, 2009 Author Share Posted September 25, 2009 I have a connection to the database above that code. When it runs I get Query was empty message. Link to comment https://forums.phpfreaks.com/topic/175489-subscription-auto-update-year/#findComment-925046 Share on other sites More sharing options...
phpbeginner Posted September 26, 2009 Author Share Posted September 26, 2009 Making some progress and here is where I am at. It is working for those where enddate < CURDATE() but it is automatically defaulting to first statement. Anyone have a suggestion? Thanks In Advance. <?php $rs=mysql_query("select * from subscribers where uniqueid=" . $userId . ""); while($row=mysql_fetch_row($rs)){ $date = $row[5]; $row[5] = strtotime($date); $row[5] = date('Y-m-d', $row[5]); } if($row[5] < "CURDATE()") { $sql = mysql_query("UPDATE subscribers set status=1, enddate=date_add(CURDATE(), interval 1 year) WHERE uniqueid=" . $userId . ""); } else { $sql2 = mysql_query("UPDATE subscribers enddate=date_add($row[5], interval 1 year) WHERE uniqueid=" . $userId . ""); } ?> Link to comment https://forums.phpfreaks.com/topic/175489-subscription-auto-update-year/#findComment-925395 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.