Page 1 of 1

Parse error

Posted: Sun Oct 29, 2006 5:51 am
by oskare100
Hello,
This is my code:

Code: Select all

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

// check the payment_status is Completed
if ($payment_status == "Completed")
{

//Connect to MySQL
mysql_connect("localhost", "test", "test") or die(mysql_error());

//Select file system database
mysql_select_db("test") or die(mysql_error());

//generate the password
function createRandomPassword() {

    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $pass = '' ;
        
      while ($i <= 7) {
          $num = rand() % 30;
          $tmp = substr($chars, $num, 1);
          $pass = $pass . $tmp;
          $i++;
       }

      return $pass;

   }

$password = createRandomPassword();
$password_encrypt = md5("$password");

//Add group ID
$group_id="4";

//Add user to the download system
mysql_query("INSERT INTO dl_users (username, password, `group`, email) VALUES('$payer_email', '$password_encrypt', '$group_id', '$payer_email') ") 
or die(mysql_error());  

//Add transaction details to the database

//If it is an acution payment
if ($for_auction == "true")(

//Send welcome message if auction payment
$to      = $payer_email;
$subject = ' delivery information';
$message = "
Hello,
Thank you for your purchase. You can now login to our download system and download the files.
Download system URL:
Authorized user: $first_name $last_name
Username: $payer_email (your Paypal email)
Password: $password

Best Regards
";
$headers = 'From: no-reply@test.com' . "\r\n" .
  'Reply-To: test@test.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
unset($to, $subject, $message, $headers);

) else {

//Send welcome message if standard payment
$to      = $payer_email;
$subject = 'delivery information';
$message = "
Hello,
Thank you for your purchase. You can now login to our download system and download the files.
Download system URL: 
Authorized user: $first_name $last_name
Username: $payer_email (your Paypal email)
Password: $password

Best Regards
";
$headers = 'From: no-reply@test.com' . "\r\n" .
  'Reply-To: test@test.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
unset($to, $subject, $message, $headers);
)

}

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
when I run the script I get the error "Parse error: parse error in /home/httpd/vhosts/com/httpdocs/paypal7.php on line 130"

Line 130 is the first "$to = $payer_email;" directly after "if ($for_auction == "true")(" . Here is the part of the script where line 130 is included.

Code: Select all

//If it is an acution payment
if ($for_auction == "true")(

//Send welcome message (auction payment)
$to      = $payer_email;
$subject = 'delivery information';
$message = "
Hello,
Congratulations! You have won auction $item_number ($item_name). You can now login to our download system and download the files.
Authorized user: $first_name $last_name
Username: $payer_email (your Paypal email)
Password: $password

Best Regards
";
$headers = 'From: no-reply@test.com' . "\r\n" .
  'Reply-To: test@test.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
unset($to, $subject, $message, $headers);

//Else it is a standard payment
) else {
Best Regards
Oskar R

Posted: Sun Oct 29, 2006 5:58 am
by Chris Corbyn

Code: Select all

if ($for_auction == "true")(
That parentheses should be a curly brace:

Code: Select all

if ($for_auction == "true"){
You have some other occurrences of that too.

Posted: Sun Oct 29, 2006 6:34 am
by oskare100
Hello,
OK, thanks, that solved that problem but now I get "Parse error: parse error in /home/httpd/vhosts/com/httpdocs/paypal7.php on line 211" but I don't have a line 211, my last line is 210 (?>). Maybe there is something else with the ( and the { just that I can't find it?

The code now:

Code: Select all

<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

//Post back to PayPal system to validate
$header .= "POST /pp/index.php 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.belahost.com', 80, $errno, $errstr, 30);

//Assign posted variables to local variables
//Basic Information
$business = $_POST['business'];
$receiver_email = $_POST['receiver_email'];
$receiver_id = $_POST['receiver_id'];
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$quantity= $_POST['quantity'];

//Advanced and Custom Information
$invoice = $_POST['invoice'];
$custom = $_POST['custom'];
$memo = $_POST['memo'];
$tax = $_POST['tax'];
$option_name1 = $_POST['option_name1'];
$option_selection1 = $_POST['option_selection1'];
$option_name2 = $_POST['option_name2'];
$option_selection2 = $_POST['option_selection2'];

//Shopping Cart Information
$num_cart_items = $_POST['num_cart_items'];

//Transaction Information
$payment_status = $_POST['payment_status'];
$pending_reason = $_POST['pending_reason'];
$reason_code = $_POST['reason_code'];
$txn_id = $_POST['txn_id'];
$parent_txn_id = $_POST['parent_txn_id'];
$txn_type = $_POST['txn_type'];
$payment_type = $_POST['payment_type'];

//Currency and Exchange Information
$mc_gross = $_POST['mc_gross'];
$mc_fee = $_POST['mc_fee'];
$mc_currency = $_POST['mc_currency'];
$settle_amount = $_POST['settle_amount'];
$settle_currency = $_POST['settle_currency'];
$exchange_rate = $_POST['exchange_rate'];
$payment_gross = $_POST['payment_gross'];
$payment_fee = $_POST['payment_fee'];

//Auction Information
$for_auction = $_POST['for_auction'];
$auction_buyer_id = $_POST['auction_buyer_id'];
$auction_closing_date= $_POST['auction_closing_date'];
$auction_multi_item = $_POST['auction_multi_item'];

//Buyer Information
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payer_business_name = $_POST['payer_business_name'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip= $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$payer_email = $_POST['payer_email'];
$payer_id = $_POST['payer_id'];
$payer_status= $_POST['payer_status'];

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

// Check if the payment_status is Completed
if ($payment_status == "Completed")
{

//Connect to MySQL
mysql_connect("localhost", "test", "test") or die(mysql_error());

//Select file system database
mysql_select_db("test") or die(mysql_error());

//generate the password
function createRandomPassword() {

    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double)microtime()*1000000);
    $i = 0;
    $pass = '' ;
        
      while ($i <= 7) {
          $num = rand() % 30;
          $tmp = substr($chars, $num, 1);
          $pass = $pass . $tmp;
          $i++;
       }

      return $pass;

   }

$password = createRandomPassword();
$password_encrypt = md5("$password");

//Add group ID
$group_id="4";

//Add user to the download system
mysql_query("INSERT INTO dl_users (username, password, `group`, email) VALUES('$payer_email', '$password_encrypt', '$group_id', '$payer_email') ") 
or die(mysql_error());  

//Add transaction details to the database

//If it is an acution payment
if ($for_auction == "true"){

//Send welcome message (auction payment)
$to      = $payer_email;
$subject = ' delivery information';
$message = "
Hello,
Congratulations! You have won auction ....

Best Regards
";
$headers = 'From: no-reply@test.com' . "\r\n" .
  'Reply-To: test@gmail.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
unset($to, $subject, $message, $headers);

//Else it is a standard payment
} else {

//Send welcome message (standard payment)
$to      = $payer_email;
$subject = ' delivery information';
$message = "
Hello,
Thank you for your purchase. ....

Best Regards
";
$headers = 'From: no-reply@test.com' . "\r\n" .
  'Reply-To: test@gmail.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
unset($to, $subject, $message, $headers);
}

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>

Best Regards
Oskar R

Posted: Sun Oct 29, 2006 7:40 am
by aaronhall
You're missing a closing bracket for the first if statement at the top of the file.

Posted: Sun Oct 29, 2006 8:56 am
by Z3RO21
This is the reason that when ever I write a control structure or the like I always write out the entire structure before I fill it... Saves a lot of debugging if you are the type of person who forgets to close structures. :P

Posted: Sun Oct 29, 2006 9:31 am
by Chris Corbyn
It's the reason why I:

a) Nest structures correctly
b) Use an editor which does bracket pairing