<?php
function filter($var)
{
return stripslashes(htmlspecialchars($var));
}
require_once('paypal.class.php'); // include the class file
$p = new paypal_class;
$p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (empty($_GET['action'])) $_GET['action'] = 'process';
switch ($_GET['action']) {
case 'process':
if(!isset($_POST['name']))
{
echo 'You need to enter in a username before you can purcahse VIP!';
die;
}
$swag = filter($_POST['name']);
$p->add_field('business', '[email protected]');
$p->add_field('return', 'http://'.$_SERVER['HTTP_HOST']); //The success URL
$p->add_field('custom', $swag);
$p->add_field('cancel_return', 'http://'.$_SERVER['HTTP_HOST']); // The "canceled" URL
$p->add_field('notify_url', $this_script.'?action=ipn'); //The IPN URL, the URL pointing to THIS page.
$p->add_field('item_number', 'Hotel VIP');
$p->add_field('item_name', 'Hotel VIP');
$p->add_field('amount', '£5.50');
$p->submit_paypal_post();
break;
case 'ipn':
if ($p->validate_ipn()) {
$host = "localhost";
$username = "root";
$password = "Password";
$dbname = "phoenix";
$connect = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($dbname, $connect) or die("Could not connect to database, error: ".mysql_error());
mysql_query("UPDATE users SET vip = 1 WHERE username = '".$p->ipn_data['custom']."' LIMIT 1");
mysql_query("UPDATE users SET rank = 2 WHERE username = '".$p->ipn_data['custom']."' LIMIT 1");
}
break;
}
?>