> I have a subscription service and am trying to not allow the buyer to > proceed purchasing another subscription if one of their subscriptions is > over 29 days past due in their payment. I am trying to query each invoice > and checking to see if it is past due more than 29 days, if it is I want a > message to come up saying that it can not proceed because they account is > not current. Can you look at the code below and let me know if you see > something wrong. It is not working for me. Thanks.
There's a problem in your code below, but you could just use this query: $query = "SELECT * FROM $table_name WHERE buyerid='$buyerid' AND paidinfull IS NULL AND duedate < CURDATE() - INTERVAL 29 DAY"; If that query returns any rows, the buyer is more than 29 days past due. If you need to get the days, you can do something like this: $query = "SELECT *, TO_DAYS(CURDATE()) - TO_DAYS(duedate) AS difference FROM $table_name WHERE buyerid = '$buyerid' AND paidinfull IS NULL"; Now, $row['difference'] will contain the number of days between now and their last duedate. Check in PHP if it's over 29 and act accordingly. Adapt to your needs... > > > ------START CODE---------------------------------------------------------- > > $sql_1 ="SELECT * FROM $table_name > WHERE buyerid = \"$buyerid\" AND paidinfull is NULL"; > $result_1 = @mysql_query($sql_, $connection) or die("Error #" . > mysql_errno() . ": " . mysql_error()); > > if(mysql_num_rows($result_1) > 0){ > while($row = mysql_fetch_array($result_1)) { > > $duedate1 = $row['duedate']; > $paiddate1 = $row['paiddate']; > $paidinfull = $row['paidinfull']; > > $duedatestamp = strtotime($duedate1); // due date unix > timestamp > $difference = time() - $duedatestamp; // diff in seconds > $differencedays = $difference / 86400; // 60 x 60 x 24 hours > floor > rounds the days down > $differencedays1 = floor($differencedays); > > $paiddatestamp = strtotime($paiddate1); // paid date unix timestamp > $diffdays = floor(((paiddatestamp - duedatestamp) / 86400)); You're missing some dollar signs on your variables here... > > > if (!$paiddate1) > { > $daysout = $differencedays1; > } > else > { > $daysout = $diffdays; > } > > if ($daysout > 29) > { > echo "You cannot add this product as your account is 30 days past due"; > exit; > } ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php