Jump to content

Recommended Posts

well actually it is functioning exactly like I told it, but it's not what I wanted.  Ok I did paypay integration,there is a time period on the database that is set to the number of days they paid for 30 or 365 which is 5.99 or 19.99.
everything works on the site now, I test everything as I do it, I was trying to get this to work, and it looked perfect, but when I retested it, I found out it's not functioning like I envisioned.
[code]

<?php
if($_SESSION['controller'] === true) { // updates paid time period
$select = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]';";
$query = mysql_query($select);
$row = mysql_fetch_array($query);
if ($row['timeperiod'] != "none") {
$currentdate = date("m/d/y");
$paydate = $row['paydate'];
$currentdate = strtotime($currentdate);
$paydate = strtotime($paydate);
$number_days = floor(($currentdate - $paydate)/86400); // 86400 = seconds per day
$updatedversion = $row['timeperiod'] - $number_days;
$update = "UPDATE userinfo SET timeperiod = '$updatedversion' WHERE username = '$_SESSION[username]';";
$query2 = mysql_query($update);
} // Closes check for timeperiod equaling none.
$selectinfo = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]' AND timeperiod <= 0;";
$query3 = mysql_query($selectinfo);
if ($rowforupdate = mysql_fetch_array($query3)) {
$paid = "no";
$paypalid = "not applicable";
$paydate = "not applicable";
$timeperiod = "none";
$updatepayinfo = "UPDATE userinfo SET paid = '$paid', paypalid = '$paypalid', paydate = '$paydate', timeperiod = '$timeperiod' WHERE id = '$_SESSION[id]';";
$query4 = mysql_query($updatepayinfo);
}// closes row to update payement information when number is 0 or below
}// closes test to update paid
}// close isset

?>[/code]
1. I test to see if my session is active, this is hte basis for all of this script to run.
2. It queries the database for information so I can use it in my script.  It calls the information using the user id number so there is no chance of error, I don't allow the same username in the database, but it's a safety precaution.
3. I check to see if timeperiod in the database is not set to none, if it's not then I run through an update script.
4. I pull all the date information together, and calculate it.( the intention is, I pull the date from the database, which is the date they paid, then I pull the current date, which is whatever today is, I then calculate the amount of days that passed in those time period, the timeperiod in the database is the days left on the active paid account.  After I calculate it, I subtract the new update, to the timeperiod, giving me the new appropriate sum.  and I look to see what itme period has, if it is less than or equal to 0 then I know the paid account is invalid, and do the proper actions to be able to change all teh information on the account to show there payment has been finished.  This also opens up the option for them to buy again on another page.
This is what I want to happen, but I didn't take this into account until it was too late, when someone log's in, it runs this script, if they log in again it runs it again, what can I do "if anything" to modify this script to update it properly, but not reupdate it every time they login, this doubles it.  If it has been 3 days, The only thing that crossed my mind, I am going to try now, but I still wanted advice in case it doesn't work, the last idea I had was do a quick test in the middle of the script, to see if the updated number is already finished, but I won't know how to integrate that in there anyway.  Any advice??
5. I do the database update to update the time period.
6. then I query the db again to make sure I have all updated information from my query,
Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/
Share on other sites

[code]
<?php
if($_SESSION['controller'] === true) { // updates paid time period
$select = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]';";
$query = mysql_query($select);// query for info
$row = mysql_fetch_array($query); // fetch array
if ($row['timeperiod'] != "none") { // check status of timeperiod
$currentdate = date("m/d/y");// get's todays date
$paydate = $row['paydate']; // get's db pay date
$currentdate = strtotime($currentdate); // changes to time stamp
$paydate = strtotime($paydate);
$number_days = floor(($currentdate - $paydate)/86400); // 86400 = seconds per day
$updatedversion = $row['timeperiod'] - $number_days; // new time period
$checkforupdate = "SELECT timeperiod FROM userinfo WHERE id = '$SESSION[id]' AND timeperiod != '$updatedversion';";
$checkquery = mysql_query($checkforupdate);
if ($checkrow = mysql_fetch_array($checkquery)) {
$update = "UPDATE userinfo SET timeperiod = '$updatedversion' WHERE username = '$_SESSION[username]';";
$query2 = mysql_query($update);
}
} // Closes check for timeperiod equaling none.
$selectinfo = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]' AND timeperiod <= 0;";
$query3 = mysql_query($selectinfo);
if ($rowforupdate = mysql_fetch_array($query3)) {
$paid = "no";
$paypalid = "not applicable";
$paydate = "not applicable";
$timeperiod = "none";
$updatepayinfo = "UPDATE userinfo SET paid = '$paid', paypalid = '$paypalid', paydate = '$paydate', timeperiod = '$timeperiod' WHERE id = '$_SESSION[id]';";
$query4 = mysql_query($updatepayinfo);
}// closes row to update payement information when number is 0 or below
}// closes test to update paid
?>
[/code]
I may not be a grand master yet, but I am getting a hell of a lot better, I figured it out, but thanks for hte help, I ran a check before updating to see if the current update had already been made, i have to think for a minute to figure out if checking another day is going to mess it up
Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/#findComment-65134
Share on other sites

I think I uncovered another issue.
How am I going to check for it each day, because again, if today it checks, then checks again today, it won't update.
But if tomorrow for instance, it will check again, and update more than necessary.
I may have to factor in another date, that shows last time updated, or something?  hmm, I could update the current date, hmm
any advice???
Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/#findComment-65136
Share on other sites

I guess now I actually do need help, I worked on the script some more, I supposedly had it set up right, most of the functionality is there, but there are some quirks, I play around with one of the dates, to see what will happen when it updates tomorrow or the next day and it's acting up a little, it'll either throw the time period somewhere up in the thousands, or it will start increasing it by just a few.  Can someone help me understand what is causing this.
[code]
<?php
if($_SESSION['controller'] === true) { // updates paid time period
$select = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]';";
$query = mysql_query($select);// query for info
$row = mysql_fetch_array($query); // fetch array
if ($row['timeperiod'] != "none") { // check status of timeperiod
$currentdate = date("m/d/y");// get's todays date
$paydate = $row['paydate']; // get's db pay date
$currentdate = "07/29/06"; //strtotime($currentdate); // changes to time stamp
$paydate = strtotime($paydate);
$datetoupdate = date("m/d/y");
$number_days = floor(($currentdate - $paydate)/86400); // 86400 = seconds per day
$updatedversion = $row['timeperiod'] - $number_days; // new time period
$checkforupdate = "SELECT timeperiod FROM userinfo WHERE id = '$_SESSION[id]' AND timeperiod != '$updatedversion';";
$checkquery = mysql_query($checkforupdate);
if ($checkrow = mysql_fetch_array($checkquery)) {
$update = "UPDATE userinfo SET timeperiod = '$updatedversion', paydate = '$datetoupdate' WHERE username = '$_SESSION[username]';";
$query2 = mysql_query($update);
}
} // Closes check for timeperiod equaling none.
$selectinfo = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]' AND timeperiod <= '0';";
$query3 = mysql_query($selectinfo);
if ($rowforupdate = mysql_fetch_array($query3)) {
$paid = "no";
$paypalid = "not applicable";
$paydate = "not applicable";
$timeperiod = "none";
$updatepayinfo = "UPDATE userinfo SET paid = '$paid', paypalid = '$paypalid', paydate = '$paydate', timeperiod = '$timeperiod' WHERE id = '$_SESSION[id]';";
$query4 = mysql_query($updatepayinfo);
}// closes row to update payement information when number is 0 or below
}// closes test to update paid
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/#findComment-65144
Share on other sites

I also added in some functionality, I started updating the paydate, to the current date, and left a note for the user's that this is showing when the timeperiod was last updates, then it started doing those errors when I started commenting out the current date, and adding a date that was a few days in advance??
Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/#findComment-65147
Share on other sites

[B]strtotime()[/B] has issues with certian date formats, so you're probably getting invalid timestamps when you pass the function a date in ("m/d/y") format. According to the [url=http://www.gnu.org/software/tar/manual/html_node/tar_109.html]GNU Dates Input Format[/url], one of the best recommeded formats is ("Y-m-d"). Ensure that the [B]paydate[/B] value in your database is in this same format, so you will be comparing timestamps correctly.

Also, there should be no need for you to update the [B]paydate[/B] field in your database when you are simply checking is there are days left in [B]timeperiod[/B]. Also, this will cause you to have incorrect information on when a user last paid, so I would only update this value when a user pays for an extended time period, or their timeperiod expires.

Lastly, you are making up to 5 database calls (3 "SELECT", 2 "UPDATE") where you only need 2 (One "SELECT", One "UPDATE"). Here is some revised code including my two recommendations:

[code=php:0]
if($_SESSION['controller'] === true) { // updates paid time period
$select = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]';";
$query = mysql_query($select);// query for info
$row = mysql_fetch_array($query); // fetch array

if ($row['timeperiod'] != "none") { // check status of timeperiod
$currentdate = strtotime(date("Y-m-d"); // get todays date, changed to timestamp
$paydate = strtotime($row['paydate']); // change paydate to timestamp
$number_days = floor(($currentdate - $paydate)/86400); // 86400 = seconds per day
$updatedversion = $row['timeperiod'] - $number_days; // new time period

if ($row['timeperiod'] != $updatedversion) {
if ($updatedversion <= 0) {
$paid = "no";
$paypalid = "not applicable";
$paydate = "not applicable";
$timeperiod = "none";
$updatepayinfo = "UPDATE userinfo SET paid = '$paid', paypalid = '$paypalid', paydate = '$paydate', timeperiod = '$timeperiod' WHERE id = '$_SESSION[id]';";
$query4 = mysql_query($updatepayinfo);
} else {
$update = "UPDATE userinfo SET timeperiod = '$updatedversion' WHERE username = '$_SESSION[username]';";
$query2 = mysql_query($update);
}
}
}
}
[/code]

Let me know how this works out for you.
Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/#findComment-65210
Share on other sites

I tried it, but it gave me the exact same issue I had before with my original script with every login, it doubles hte results, but I redid my script and everything works perfect, just with a lot of db calls I might try to fix some of the db calls, and clean it up some, but everything functions perfectly.  I haven't tested it once it goes negative but I am about to.
[code]<?php
// start
if($_SESSION['controller'] === true) { // updates paid time period
$select = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]';";
$query = mysql_query($select);// query for info
$row = mysql_fetch_array($query); // fetch array
if ($row['timeperiod'] != "none") { // check status of timeperiod
$currentdate = "08/23/06";  //date("m/d/y");// get's todays date
$paydate = $row['paydate']; // get's db pay date
$currentdate = strtotime($currentdate); // test later with later date
$paydate = strtotime($paydate);
$datetoupdate = "08/23/06"; //date("m/d/y");
$number_days = floor(($currentdate - $paydate)/86400); // 86400 = seconds per day
$updatedversion = $row['timeperiod'] - $number_days; // new time period
$checkforupdate = "SELECT timeperiod FROM userinfo WHERE id = '$_SESSION[id]' AND timeperiod != '$updatedversion';";
$checkquery = mysql_query($checkforupdate);
if ($checkrow = mysql_fetch_array($checkquery)) {
$update = "UPDATE userinfo SET timeperiod = '$updatedversion', paydate = '$datetoupdate' WHERE username = '$_SESSION[username]';";
$query2 = mysql_query($update);
}
} // Closes check for timeperiod equaling none.
$selectinfo = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]' AND timeperiod <= '0';";
$query3 = mysql_query($selectinfo);
if ($rowforupdate = mysql_fetch_array($query3)) {
$paid = "no";
$paypalid = "not applicable";
$paydate = "not applicable";
$timeperiod = "none";
$updatepayinfo = "UPDATE userinfo SET paid = '$paid', paypalid = '$paypalid', paydate = '$paydate', timeperiod = '$timeperiod' WHERE id = '$_SESSION[id]';";
$query4 = mysql_query($updatepayinfo);
}// closes row to update payement information when number is 0 or below
}// closes test to update paid
?>[/code]
if you can help me fix some of those db calls now without breaking the functionality of the script it would help a lot.
Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/#findComment-65216
Share on other sites

see what started happening is it started running through the script every time it entered, the reason for extra db calls was to retrieve the updated version of the information, because I had to test the status on some fields, do a few updates based on that, then test it again, do some more updates then finally, test for 1 more thing, which included some previous updates in the same script, then run a few more queries.  I got everything functioning currently, it all functions like I want, so I am not being picky, If I can get it optimized, or cut down to less lines of code, to achieve the same successful result, then I don't mind giving it a try I can save my code on another page, and just pull it back if something goes wrong.
Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/#findComment-65227
Share on other sites

I'm glad you figured out your issue.

I was mentioning lowering your number of DB calls, as you seem to be updating user information with an updated value, then pulling that [B]exact same[/B] value from the DB 1 line of code later, when you had the updated version of the value already set in a variable. I just don't see the need to check the status when you have a variable that tells you the status 1 line of code earlier. Not much could have changed in that fraction of a second.

Anyway, if you want to try it, this should get rid of some of your db calls:

[code=php:0]
<?php
// start
if($_SESSION['controller'] === true) { // updates paid time period
$select = "SELECT * FROM userinfo WHERE id = '$_SESSION[id]';";
$query = mysql_query($select);// query for info
$row = mysql_fetch_array($query); // fetch array

if ($row['timeperiod'] != "none") { // check status of timeperiod
$currentdate = "08/23/06";  //date("m/d/y");// get's todays date
$paydate = $row['paydate']; // get's db pay date
$currentdate = strtotime($currentdate); // test later with later date
$paydate = strtotime($paydate);
$datetoupdate = "08/23/06"; //date("m/d/y");
$number_days = floor(($currentdate - $paydate)/86400); // 86400 = seconds per day
$updatedversion = $row['timeperiod'] - $number_days; // new time period

if($row['timeperiod'] != $updatedversion){
if($updatedversion <= 0){
$paid = "no";
$paypalid = "not applicable";
$paydate = "not applicable";
$timeperiod = "none";
$updatepayinfo = "UPDATE userinfo SET paid = '$paid', paypalid = '$paypalid', paydate = '$paydate', timeperiod = '$timeperiod' WHERE id = '$_SESSION[id]';";
$query4 = mysql_query($updatepayinfo);
} else {
$update = "UPDATE userinfo SET timeperiod = '$updatedversion', paydate = '$datetoupdate' WHERE username = '$_SESSION[username]';";
$query2 = mysql_query($update);
}
}

} // Closes check for timeperiod equaling none.
}// closes test to update paid
?>
[/code]

Link to comment
https://forums.phpfreaks.com/topic/15883-script-not-functioning/#findComment-65255
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.