Jump to content

Recommended Posts

Hi, I am trying to write a payment script for my registration script that I have written. At the moment I am just trying to get the payment script to work itself.

 

I have written a form that actions the script below, and get an error:

 

 

Parse error: syntax error, unexpected T_ELSE in /home/moveitho/public_html/sitebuilder/payment.php on line 73

 

How can I fix this, and have I done anything else wrong? Any help is much appreciated.

 

<?php

# This opens the IPN log file and logs the time of payment
$filename = "data/ipn.log";
$log = fopen( $filename, "a");
fwrite($log, "\n\nipn - " . gmstrftime ("%b %d %Y %H:%M:%S", time()) . "\n");

# This connects to the defined database 

include_once("data/required.php");

$db1 = mysql_connect("localhost", $dbuser, $dbpass);
mysql_select_db($db, $db1);

# This creates a reply to validate the IPN

$postvars = array();
while (list ($key, $value) = each ($HTTP_POST_VARS)) {
$postvars[] = $key;
}
$req = 'cmd=_notify-validate';
for ($var = 0; $var < count ($postvars); $var++) {
$postvar_key = $postvars[$var];
$postvar_value = $$postvars[$var];
$req .= "&" . $postvar_key . "=" . urlencode($postvar_value);
}

# Create the HTTP header for the reply message

$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);

# Write the payment details to the log file

fwrite($log, "Values: ". $sub_no." ". $mail_from." ". $subscription_name." ". $payment_status."
". $pending_reason." ". $payment_date." ". $price." ". $currency." ". $first_name." ". $last_name." ". $house_no."
". $address." ". $town." ". $county." ". $postcode." ". $country." ". $email." ". $subscription_status."
". $verify_sign." ". $referal_if. "\n");

# Check the HTTP connection to PayPal is successful

if (!$fp) {
print "$errstr ($errno)";
fwrite($log, "HTTP connection was unsuccessful!");
$res = "FAILED";
}

# Posts variables to PayPal's server. If payment was successful, a verified response is returned

else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

# If payment was successful 

if (strcmp ($payment_status, "Completed") == 0) {
mysql_query("UPDATE Users SET verified = 'yes' WHERE username='$username'");

send_reg();

# Payment has not been completed

} else {

print "Payment not complete";

# Unverified payment

} else {

print "Suspicious payment";

}
}
}
}
# Insert details into databse

$query = "INSERT into payment ( sub_no, mail_from, subscription_name, payment_status, pending_reason,
payment_date, price, currency, first_name, last_name, house_no, address, town, county, postcode, country, email,
subscription_status, verify_sign, referal_if )
VALUES
( '$_POST[sub_no]', '$_POST[mail_from]', '$_POST[subscription_name]', '$_POST[payment_status]', '$_POST[pending_reason]',
'$_POST[payment_date]', '$_POST[price]', '$_POST[currency]', '$_POST[first_name], '$_POST[last_name]', '$_POST[house_no]',
'$_POST[address]', '$_POST[town]', '$_POST[county]', '$_POST[postcode]', '$_POST[country]', '$_POST[email]',
'$_POST[subscription_status]', '$_POST[verify_sign]', '$_POST[referal_if]' ) ";

$result = mysql_query($query, $db);

# Close files and database

fclose ($fp);
fclose ($log);
mysql_close($db);
?> 

Link to comment
https://forums.phpfreaks.com/topic/147641-help-with-php-and-paypal-script/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.