Hi guys
I have a script currently working however I am trying to add a SQL command within the script to update a database.
<?php
session_start();
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
$ip = $_SERVER['REMOTE_ADDR'];
$amt = 0.01;
$url=$_SERVER['REQUEST_URI'];
if(strstr($url,'2diWrwJlDa')){
$amt=0.01;
}
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = strtolower($_POST['payment_status']);
$payment_amount = $_POST['mc_gross'];
$sub_status = $_POST['txn_type'];
$sub_amount = $_POST['mc_amount3'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$business = $_POST['business'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
/* ------- Feel free to add any variables above ------
------- that you wish to retrieve from PayPal ----- */
if (!$fp) {
unable();
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$payment_status = strtolower($payment_status);
$sub_status = strtolower($sub_status);
$verifyNum=0;
if((strstr($payment_status,"comp"))||(strstr($sub_status,"signup"))||(strstr($sub_status,"payment"))){$verifyNum++;}
else if(strstr($sub_status,"cancel")){fclose ($fp);exit;}
else{$reason1 = "Payment/Subscription Status Not Complete.";}
$receiver="stevegodders@hotmail.com";
if((strstr($receiver,$receiver_email))||($business=="stevegodders@hotmail.com")){$verifyNum++;}
else{$reason2 = "Payment Receiver Email not correct.";}
if((($payment_amount == $amt)||($sub_amount == $amt)) && (strtolower($payment_currency) == "gbp")){$verifyNum++;}
else{
if(strtolower($payment_currency) != "gbp"){$cur=strtoupper('gbp');$reason3 = "Currency is set at $payment_currency and not $cur";}
else{$reason3 = "Payment amount has been tampered with.";}
}
// IF ERRORS FOUND
if(($verifyNum < 3)&&($ip != "216.113.188.202")){
$headrs = "From: Payment Error Report <email@hotmail.com>\n";
$headrs .= "Content-type: text/plain;\r\n";
$sendToMe = "email@hotmail.com";
$errSub = "IPN Payment Error Reporting\n";
$errMessage = "
There has been an Error with the following Payment >>>
Transaction ID: $txn_id
Reciever Email: $receiver_email
Payee Email: $payer_email
Logged IP: $ip
Reasons:
$reason1
$reason2
$reason3
Please investigate.
Instant IPN Generator Payment Error Reporting.";
mail($sendToMe,$errSub,$errMessage,$headrs);
isError($ip);
exit;
}
else if($verifyNum == 3){
/* -----------------------------
If you'd like to add the PayPal information to
a database or email your buyer, you can add any
code here between the two headers:
BEGIN EDITABLE AREA ---------- */
mysql_connect("localhost", "XXXXX", "XXXXX")or die("cannot connect");
mysql_select_db("XXXXX")or die("cannot select DB");
[color=red]"UPDATE qls3_users SET group_id = '9' WHERE $payer_email = 'email'";[/color] <<<< THIS IS THE BIT THAT DONT SEEM TO WORK
/* END EDITABLE AREA ------------ */
header("location:undefined");
exit;
}
else {
unable();
}
}
else if (strcmp ($res, "INVALID") == 0) {
$headrs = "From: betbox Payment Error <email@hotmail.com>\n";
$headrs .= "Content-type: text/plain;\r\n";
$sendToMe = "email.com";
$errSub = "IPN Payment Error Reporting\n";
$errMessage = "
There has been an Error with the following Payment >>>
Logged IP: $ip
Reasons:
Payment came back as INVALID. Possible direct view or attempt at Fraud.
Please investigate.
Instant IPN Generator Payment Error Reporting.";
mail($sendToMe,$errSub,$errMessage,$headrs);
isError($ip);
}
}
fclose ($fp);
}
function isError($ip){
echo "<p>Sorry, there was an error with your payment.</p>";
if($ip){
echo "<p>Your IP address of $ip has been logged for further investigation.</p>";
}
echo "<p>If you have purchased this product and are seeing this error, please contact us at<br><a href=\"mailto:email.com\" style=\"color:#AA0000;\">email.com</a> and quote your PayPal Transaction ID.<br><br>Thank You,<br>bet fair.<br><a href=\"http://www.betfairbettingsoftware.com\" style=\"color:#AA0000;\">http://www.example.com</a></p>";
}
function unable(){
?>
<head>
<title>http://www.exampl.com Payment Error</title>
</head>
<body>
<div style="text-align:center;">
<div style="margin:10px auto 10px auto;width:600px;background:#F0F0F0;padding:20px;text-align:left;border:solid 3px #FF0000;font-family:arial;font-size:13px;">
<p>We are very sorry, there seems to be some difficulty processing your Payment.</p>
<p>This may be an error related to our Web Site communicating with PayPal's Web Site. We are very sorry for the inconvenience. Your payment may have been received regardless of this error.</p>
<p>Please log into your PayPal account and verify whether or not this transaction has been completed. If so, please contact us at <a href="mailto:email.com" style="color:#AA0000;">email addy</a>. Please quote the Transaction ID in your correspondence.</p>
<p>If your PayPal account shows no indication of this transaction having been completed, feel free to try purchasing again on our <a href="http://www.example.com" style="color:#AA0000;">Web Site</a>. If, inadvertently, you are double charged through this course of action, we will refund one of your purchases immediately.</p>
<p>Once again, we are sorry for your inconvenience.</p>
<p>Kind Regards,<br>
<br>
http://www.example.com</p>
</div>
</div>
</body>
<?
}
?>
Does anyone have a way to resolve this. Basically All i need to do is when I get the IPN is update a datasebase group ID to 9 for a user whos email address is the same as that used in paypal?