Hi,
Hope you are ok. I made a website to recieve donations in from other people. It is possible to check if this coding hereunder are working or not?
Thanks for your help.
Donation page:
<?php
require "config.php";
require "dbconnection/connection.php";
// Determining the URL of the page:
$url = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"]);
// Fetching the number and the sum of the donations:
list($number,$sum) = mysql_fetch_array(mysql_query("SELECT COUNT(*),SUM(amount) FROM dc_donations"));
// Calculating how many percent of the goal were met:
$percent = round(min(100*($sum/$goal),100));
// Building a URL with Google's Chart API:
$chartURL = 'http://chart.apis.google.com/chart?chf=bg,s,f9faf7&cht=p&chd=t:'.$percent.',-'.(100-$percent).'&chs=200x200&chco=639600&chp=1.57';
?>
<!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>Funds</title>
<link rel="stylesheet" type="text/css" href="stylesheets/styles.css" />
</head>
<body>
<div id="wrapper">
<div id="content">
<div id="scope">
<h2>Welcome Visitor!!!</h2>
<p></p>
</div>
<div id="donationsection">
<h2>Donate for this cause.</h2>
<form action="<?php echo $payPalURL?>" method="post" class="payPalForm">
<div id="form">
<input type="hidden" name="cmd" value="_donations" />
<input type="hidden" name="item_name" value="Donation" />
<!-- Your PayPal email: -->
<input type="hidden" name="business" value="<?php echo $myPayPalEmail?>" />
<!-- PayPal will send an IPN notification to this URL: -->
<input type="hidden" name="notify_url" value="<?php echo $url.'/ipn.php'?>" />
<!-- The return page to which the user is navigated after the donations is complete: -->
<input type="hidden" name="return" value="<?php echo $url.'/thankyou.php'?>" />
<!-- Signifies that the transaction data will be passed to the return page by POST -->
<input type="hidden" name="rm" value="2" />
<!-- General configuration variables for the paypal landing page. Consult
http://www.paypal.com/IntegrationCenter/ic_std-variable-ref-donate.html for more info -->
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="cbt" value="Go Back To The Site" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="currency_code" value="EUR" />
<!-- The amount of the transaction: -->
<select name="amount">
<option value="50">€50</option>
<option value="20">€20</option>
<option value="10" selected="selected">€10</option>
<option value="5">€5</option>
</select>
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest" />
<!-- You can change the image of the button: -->
<!--<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!" />-->
<input type="submit" name="submit" value="Donate" />
<!--<img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />-->
</div>
</form>
The Goal is €20.000 and <?php echo $percent?>% done
</div>
</div>
<div id="comments">
<h4>Comments from who show the support!!</h4>
<?php
$comments = mysql_query("SELECT * FROM dc_comments ORDER BY id DESC");
// Building the Donor List:
if(mysql_num_rows($comments))
{
while($row = mysql_fetch_assoc($comments))
{
?>
<table>
<tr>
<td id="id"><?php echo $row["id"];?></td>
<td id="name"><?php echo $row["name"];?></td>
<td id="date"><?php echo $row["dt"];?></td>
</tr>
<tr>
<td colspan="3"><?php echo $row["messege"];?></td>
</tr>
</table>
<?php
}
}
?>
</div>
</div>
</body>
</html>
config page:
<?php
// Fill your PayPal email below.
// This is where you will receive the donations.
$myPayPalEmail = 'your@email.com';
// The paypal URL:
$payPalURL = 'https://www.paypal.com/cgi-bin/webscr';
// Your goal in EUR:
$goal = 15000;
// Demo mode is set - set it to false to enable donations.
// When enabled PayPal is bypassed.
/*$demoMode = true;
if($demoMode)
{
$payPalURL = 'demo_mode.php';
}*/
?>
ipn page:
<?php
require "paypal_integration_class/paypal.class.php";
require "config.php";
require "dbconnection/connection.php";
$p = new paypal_class;
$p->paypal_url = $payPalURL;
if ($p->validate_ipn()) {
if($p->ipn_data['payment_status']=='Completed')
{
$amount = $p->ipn_data['mc_gross'] - $p->ipn_data['mc_fee'];
mysql_query(" INSERT INTO dc_donations (transaction_id,donor_email,amount,original_request)
VALUES (
'".esc($p->ipn_data['txn_id'])."',
'".esc($p->ipn_data['payer_email'])."',
".(float)$amount.",
'".esc(http_build_query($_POST))."'
)");
}
}
function esc($str)
{
global $link;
return mysql_real_escape_string($str,$link);
}
?>
thankyou page:
<?php
require "config.php";
require "dbconnection/connection.php";
if(isset($_POST['submitform']) && isset($_POST['txn_id']))
{
$_POST['nameField'] = esc($_POST['nameField']);
$_POST['websiteField'] = esc($_POST['websiteField']);
$_POST['messageField'] = esc($_POST['messageField']);
$error = array();
if(mb_strlen($_POST['nameField'],"utf-8")<2)
{
$error[] = '<p id="error">Please fill in a valid name.';
}
if(mb_strlen($_POST['messageField'],"utf-8")<2)
{
$error[] = 'Please fill in a longer message.';
}
if(!validateURL($_POST['websiteField']))
{
$error[] = 'The URL you entered is invalid.</p>';
}
$errorString = '';
if(count($error))
{
$errorString = join('<br />',$error);
}
else
{
mysql_query(" INSERT INTO dc_comments (transaction_id, name, url, message)
VALUES (
'".esc($_POST['txn_id'])."',
'".$_POST['nameField']."',
'".$_POST['websiteField']."',
'".$_POST['messageField']."'
)");
if(mysql_affected_rows($link)==1)
{
$messageString = '<a href="donate.php">You were added to our donor list! »</a>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thank you!</title>
<link rel="stylesheet" type="text/css" href="stylesheets/styles.css" />
</head>
<body>
<div id="comment">
<p id="thanks">Thank you for your donation!</p>
<form action="" method="post">
<table align="center">
<tr>
<td><label for="nameField">Name:</label></td>
<td><input type="text" id="nameField" name="nameField" /></td>
</tr>
<tr>
<td><label for="websiteField">Web Site</label></td>
<td><input type="text" id="websiteField" name="websiteField" /></td>
</tr>
<tr>
<td><label for="messageField">Message</label></td>
<td><textarea name="messageField" id="messageField"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
<input type="hidden" name="submitform" value="1" />
<input type="hidden" name="txn_id" value="<?php echo $_POST['txn_id']?>" />
</table>
</form>
<?php
if($errorString)
{
echo '<p class="error">'.$errorString.'</p>';
}
else if($messageString)
{
echo '<p class="success">'.$messageString.'</p>';
}
?>
</div>
</body>
</html>
<?php
function esc($str)
{
global $link;
if(ini_get('magic_quotes_gpc'))
$str = stripslashes($str);
return mysql_real_escape_string(htmlspecialchars(strip_tags($str)),$link);
}
function validateURL($str)
{
return preg_match('/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i',$str);
}
?>