I am testing ideas for a new section of my company's website. We're doing online magazine subscriptions and I'm trying to find the easiest way to make online renewals automatic.
I have index.html which contains a Paypal button:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form [COLOR="#FF0000"]action="handler.php"[/COLOR] method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5DEAKV4T96HFS">
<table>
<tr>
<td><input type="hidden" name="on0" value="Subscribe or Renew">
Subscribe or Renew</td>
</tr>
<tr>
<td><select name="os0">
<option value="New Online Subscription">New Online Subscription $10.00 USD</option>
<option value="Renewal">Renewal $5.00 USD</option>
</select></td>
</tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</body>
</html>
Notice that I have changed the form action to "handler.php". handler.php queries a database to update the customer's subscription expiration date. So that the customer's subscription will expire one year from the date of renewal. I know that my code doesn't exactly do this, but it still works for my purpose. Once again, I'm just testing and playing around. Here is handler.php:
$dbhost = "-------";
$dbname = "-------";
$dbuser = "-------";
$dbpass = "-------";
//Connect to server and select databse.
$con = mysql_connect("$dbhost", "$dbuser", "$dbpass");
if (!con){
die(mysql_error($con));
}
// Select the database.
mysql_select_db("$dbname", $con);
// Query
$sqlone = "SELECT * FROM test WHERE id='1'";
$result = mysql_query ("$sqlone") or die ('Error: '.mysql_error ());
$result = mysql_fetch_array($result);
$date = $result["date"];
$currentyear = substr("$date",0,4);
$currentmonthday = substr("$date",4,9);
$renewedyear = $currentyear + 1;
$reneweddate = "$renewedyear"."$currentmonthday";
// Update the database
$sqltwo = "UPDATE test SET date='$reneweddate' WHERE id = '1'";
mysql_query ("$sqltwo") or die ('Error: '.mysql_error ());
So, once the paypal button has been clicked, everything goes to handler.php, the database updates correctly, and all of the paypal variables go floating off into space never again to serve any purpose. How can I restructure this so that my database gets updated and the paypal shopping cart still works? I thought about passing all the paypal variables to handler.php, but from there how would I pass those variables along to the shopping cart? Any ideas? Any suggestions would be greatly appreciated. Thanks.