T_ELSE statement parse error...grrr!!


#1

I’m having trouble getting this very long script to work. It’s a fairly simple script it’s just long. However, I think I’ve been staring at it for so long I’m overlooking the problem.

I’m getting a T_ELSEIF parse error on the following line:
}elseif($tabid == 2){ // STATEMENT 8

Any help would be appreciated!

[code]<?php
include(’./functions/config.php’);

if(!isset($_POST[‘id’])){ // STATEMENT 1: If they didn’t enter the page from the form send them back home
print “”;
die;

}else{ // STATEMENT 1: Otherwise start the script
$id = $_POST[‘id’];
$tabid = $_POST[‘tabid’];
$table = $_POST[‘table’];

if($tabid == 1){ // STATEMENT 2
$loan_amount = $_POST[‘loan_amount’];
$p_purpose = $_POST[‘p_purpose’];
$p_value = $_POST[‘p_value’];
$p_years = $_POST[‘p_years’];
$bal_1m = $_POST[‘bal_1m’];
$bal_2m = $_POST[‘bal_2m’];

if($bal_1m != '0' || $bal_2m != '0'){ // STATEMENT 3
  $ind_1m = '1';
  $pay_1m = $_POST['pay_1m'];
  $rate_1m1 = $_POST['rate_1m1'];
  $rate_1m2 = $_POST['rate_1m2'];
  $rate_1m = $rate_1m1 . $rate_1m2;
  $fix_var_1m = $_POST['fix_var_1m'];
  $ind_2m = '1';
  $pay_2m = $_POST['pay_2m'];
}else{ // STATEMENT 3
  $ind_1m = '0';
  $ind_2m = '0';
} // CLOSE STATEMENT 3

$p_address = $_POST['prop_address'];
$p_city = $_POST['prop_city'];
$p_zip = $_POST['prop_zip'];
$borrower_fname = $_POST['borrower_fname'];
$borrower_lname = $_POST['borrower_lname'];
$d_area = $_POST['d_area'];
$d_phone1 = $_POST['d_phone'];
$d_phone2 = $_POST['d_phone2'];
$dw_area = $_POST['dw_area'];
$dw_phone1 = $_POST['dw_phone'];
$dw_phone2 = $_POST['dw_phone2'];
$email = $_POST['email'];
$emp_status = $_POST['emp_status'];
$household_income = $_POST['household_income'];
$debt_min_pay = $_POST['debt_min_pay'];
$contact_time = $_POST['contact_time'];
$ind_coborrower = $_POST['co_borrower_ind'];

if($ind_coborrower != 0){ // STATEMENT 4
  $coborrower_fname = $_POST['coborrower_fname'];
  $coborrower_lname = $_POST['coborrower_lname'];
  $coborrower_emp_status = $_POST['coborrow_emp'];
}else{ // STATEMENT 4
  $coborrower_fname = '';
  $coborrower_lname = '';
  $coborrower_emp_status = '';
} // CLOSE STATEMENT 4

mysql_query("UPDATE refi_leads SET loan_amount='$loan_amount', p_purpose='$p_purpose', p_value='$p_value', p_years='$p_years', ind_1m='$ind_1m', bal_1m='$bal_1m', pay_1m='$pay_1m', rate_1m='$rate_1m', fix_var_1m='$fix_var_1m', ind_2m='$ind_2m', bal_2m='$bal_2m', pay_2m='$pay_2m', p_address='$p_address', p_city='$p_city', p_zip='$p_zip', borrower_fname='$borrower_fname', borrower_lname='$borrower_lname', d_area='$d_area', d_phone='$d_phone1-$d_phone2', dw_area='$dw_area', dw_phone='$dw_phone1-$dw_phone2', email='$email', emp_status='$emp_status', household_income='$household_income', debt_min_pay='$debt_min_pay', contact_time='$contact_time', ind_coborrower='$ind_coborrower', coborrower_fname='$coborrower_fname', coborrower_lname='$coborrower_lname', coborrower_emp_status='$coborrower_emp_status' WHERE id='$id'")
or die(mysql_error());

}elseif($tabid == 2){ // STATEMENT 2
$p_price = $_POST[‘p_price’];
$found_home_type = $_POST[‘found_home_type’];
$p_city = $_POST[‘p_city’];
$p_zip = $_POST[‘p_zip’];
$down_payment_percent = $_POST[‘down_payment_percent’];
$own_rent_type = $_POST[‘own_rent_type’];
$ind_reagent = $_POST[‘ind_reagent’];
$ind_pcontract = $_POST[‘ind_pcontract’];
$purchase_timeframe = $_POST[‘purchase_timeframe’];
$borrower_fname = $_POST[‘borrower_fname’];
$borrower_lname = $_POST[‘borrower_lname’];
$m_address = $_POST[‘m_address’];
$m_state = $_POST[‘m_state’];
$m_city = $_POST[‘m_city’];
$m_zip = $_POST[‘m_zip’];
$d_area = $_POST[‘d_area’];
$d_phone1 = $_POST[‘d_phone’];
$d_phone2 = $_POST[‘d_phone2’];
$dw_area = $_POST[‘dw_area’];
$dw_phone1 = $_POST[‘dw_phone’];
$dw_phone2 = $_POST[‘dw_phone2’];
$email = $_POST[‘email’];
$contact_time = $_POST[‘contact_time’];
$emp_status = $_POST[‘emp_status’];
$household_income = $_POST[‘household_income’];
$debt_min_pay = $_POST[‘debt_min_pay’];
$ind_coborrower = $_POST[‘ind_coborrower’];

if($ind_coborrower != 0){ // STATEMENT 5
  $coborrower_fname = $_POST['coborrower_fname'];
  $coborrower_lname = $_POST['coborrower_lname'];
  $coborrower_emp_status = $_POST['coborrower_emp_status'];
}else{ // STATEMENT 5
  $coborrower_fname = '';
  $coborrower_lname = '';
  $coborrower_emp_status = '';
} // CLOSE STATEMENT 5

mysql_query("UPDATE purchase_leads SET p_price='$p_price', m_address='$m_address', m_city='$m_city', m_zip='$m_zip', borrower_fname='$borrower_fname', borrower_lname='$borrower_lname', d_area='$d_area', d_phone='$d_phone1-$d_phone2', dw_area='$dw_area', dw_phone='$dw_phone1-$dw_phone2', email='$email', emp_status='$emp_status', household_income='$household_income', debt_min_pay='$debt_min_pay', contact_time='$contact_time', ind_coborrower='$ind_coborrower', coborrower_fname='$coborrower_fname', coborrower_lname='$coborrower_lname', coborrower_emp_status='$coborrower_emp_status', found_home_type='$found_home_type', p_zip='$p_zip', down_payment_percent ='$down_payment_percent', own_rent_type='$own_rent_type', ind_reagent='$ind_reagent', ind_pcontract='$ind_pcontract', purchase_timeframe='$purchase_timeframe', m_state='$m_state', p_city='$p_city' WHERE id='$id'")
or die(mysql_error());

} // CLOSE STATEMENT 2

$goto = ‘validate’;

if($goto == ‘validate’){ // STATEMENT 6
$query = mysql_query(“SELECT * FROM $table WHERE id=’$id’”);

while($r = mysql_fetch_array($query)){ // STATEMENT 7
  $ip = $r['ip'];
  $date_received = $r['date_received'];
  $p_descr = $r['p_descr'];
  $cred_hist = $r['cred_hist'];
  $p_state = $r['p_state'];
  $borrower_fname = $r['borrower_fname'];
  $borrower_lname = $r['borrower_lname'];
  $d_area = $r['d_area'];
  $d_phone = $r['d_phone'];
  $dw_area = $r['dw_area'];
  $dw_phone = $r['dw_phone'];
  $email = $r['email'];
  $emp_status = $r['emp_status'];
  $household_income = $r['household_income'];
  $debt_min_pay = $r['debt_min_pay'];
  $contact_time = $r['contact_time'];
  $ind_coborrower = $r['ind_coborrower'];
  $coborrower_fname = $r['coborrower_fname'];
  $coborrower_lname = $r['coborrower_lname'];
  $coborrower_emp_status = $r['coborrower_emp_status'];
  $product = $r['product'];
  $p_city = $r['p_city'];
  $p_zip = $r['p_zip'];

  if($tabid == '1'){ // STATEMENT 8
    $loan_amount = $r['loan_amount'];
    $p_purpose = $r['p_purpose'];
    $p_value = $r['p_value'];
    $ltv = $loan_amount / $p_value;
    $p_years = $r['p_years'];
    $ind_1m = $r['ind_1m'];
    $bal_1m = $r['bal_1m'];
    $pay_1m = $r['pay_1m'];
    $rate_1m = $r['rate_1m'];
    $fix_var_1m = $r['fix_var_1m'];
    $bal_2m = $r['bal_2m'];
    $pay_2m = $r['pay_2m'];
    $p_address = $r['p_address'];

    // Find partners that can receive the lead
    $query2 = mysql_query("SELECT * FROM partner_filters WHERE product='$product' AND min_loan_amount <= '$loan_amount' AND min_p_value <= '$p_value' AND max_ltv >= '$ltv' AND state='$p_state' ORDER BY cpl LIMIT 0,1");
    $number = mysql_num_rows($query2);

    while($t = mysql_fetch_array($query2)){ // STATEMENT 9
      $partid = $t['partid'];

      if($number == 0){ // STATEMENT 10
        print "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php?pg=sorry'>";
        die;
      } // CLOSE STATEMENT 10

      $query3 = mysql_query("SELECT * FROM partners WHERE id='$partid'");

      while($a = mysql_fetch_array($query3)){ // STATEMENT 11
        $active = $a['active_flag'];
        $Host = $a['post_host'];
        $URI = $a['post_url'];
        $ftp_username = $a['ftp_username'];
        $ftp_password = $a['ftp_password'];
        $method = $a['method'];
        $daily_cap = $a['daily_cap'];
        $aid = $a['affiliate_id'];
        $cid = $a['campaign_id'];

        // Count the number of leads sent today
        $query4 = mysql_query("SELECT * FROM refi_leads WHERE lead_buyer='$partid' AND date_received like date('Y-m-d')");
        $num = mysql_num_rows($query4);
        if($active == 0 || $num >= $daily_cap){ // STATEMENT 12
          print "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php?pg=sorry'>";
          die;
        } // CLOSE STATEMENT 12

        // Call up field names
        $query5 = mysql_query("SELECT * FROM partners_refi_fields WHERE partid='$partid'");

        while($b = mysql_fetch_array($query5)){ // STATEMENT 13
          $field_ipaddress = $b['field_ipaddress'];
          $field_datereceived = $b['field_datereceived'];
          $field_product = $b['field_product'];
          $field_p_descr = $b['field_p_descr'];
          $field_cred_hist = $b['field_cred_hist'];
          $field_loan_amount = $b['field_loan_amount'];
          $field_p_purpose = $b['field_p_purpose'];
          $field_p_value = $b['field_p_value'];
          $field_p_years = $b['field_p_years'];
          $field_1m_ind = $b['field_1m_ind'];
          $field_bal_1m = $b['field_bal_1m'];
          $field_fix_var_1m = $b['field_fix_var_1m'];
          $field_pay_1m = $b['field_pay_1m'];
          $field_rate_1m = $b['field_rate_1m'];
          $field_rate_2m = $b['field_rate_2m'];
          $field_2m_ind = $b['field_2m_ind'];
          $field_bal_2m = $b['field_bal_2m'];
          $field_pay_2m = $b['field_pay_2m'];
          $field_prop_address = $b['field_prop_address'];
          $field_prop_city = $b['field_prop_city'];
          $field_prop_state = $b['field_prop_state'];
          $field_prop_zip = $b['field_prop_zip'];
          $field_borrower_fname = $b['field_borrower_fname'];
          $field_borrower_lname = $b['field_borrower_lname'];
          $field_d_area = $b['field_d_area'];
          $field_d_phone = $b['field_d_phone'];
          $field_dw_area = $b['field_dw_area'];
          $field_dw_phone = $b['field_dw_phone'];
          $field_email = $b['field_email'];
          $field_contact_time = $b['field_contact_time'];
          $field_emp_status = $b['field_emp_status'];
          $field_household_income = $b['field_household_income'];
          $field_debt_min_pay = $b['field_debt_min_pay'];
          $field_coborrow_ind = $b['field_coborrow_ind'];
          $field_coborrow_emp = $b['field_coborrow_emp'];
          $field_coborrow_fname = $b['field_coborrow_fname'];
          $field_coborrow_lname = $b['field_coborrow_lname'];
          $field_affiliate_id = $b['field_affiliate_id'];
          $field_campaign_id = $b['field_campaign_id'];

          if($method == 'post'){ // STATEMENT 14

            if (isset($field_datereceived) && $field_datereceived!=""){ // STATEMENT 15
              $ReqBody .= "$field_datereceived=$date_received&";
            } // CLOSE STATEMENT 15

            if (isset($field_ipaddress) && $field_ipaddress!=""){ // STATEMENT 16
              $ReqBody .= "$field_ipaddress=$ip&";
            } // CLOSE STATEMENT 16

            if (isset($field_product) && $field_product!=""){ // STATEMENT 17
              $ReqBody .= "$field_product=$product&";
            } // CLOSE STATEMENT 17

            if (isset($field_p_descr) && $field_p_descr!=""){ // STATEMENT 18
              $ReqBody .= "$field_p_descr=$p_descr&";
            } // CLOSE STATEMENT 18

            if (isset($field_cred_hist) && $field_cred_hist!=""){ // STATEMENT 19
              $ReqBody .= "$field_cred_hist=$cred_hist&";
            } // CLOSE STATEMENT 19

            if (isset($field_loan_amount) && $field_loan_amount!=""){ // STATEMENT 20
              $ReqBody .= "$field_loan_amount=$loan_amount&";
            } // CLOSE STATEMENT 20

            if (isset($field_p_purpose) && $field_p_purpose!=""){ // STATEMENT 21
              $ReqBody .= "$field_p_purpose=$p_purpose&";
            } // CLOSE STATEMENT 21

            if (isset($field_p_value) && $field_p_value!=""){ // STATEMENT 22
              $ReqBody .= "$field_p_value=$p_value&";
            } // CLOSE STATEMENT 22

            if (isset($field_p_years) && $field_p_years!=""){ // STATEMENT 23
              $ReqBody .= "$field_p_years=$p_years&";
            } // CLOSE STATEMENT 23

            if (isset($field_1m_ind) && $field_1m_ind!=""){ // STATEMENT 24
              $ReqBody .= "$field_1m_ind=$1m_ind&";
            } // CLOSE STATEMENT 24

            if (isset($field_bal_1m) && $field_bal_1m!=""){ // STATEMENT 25
              $ReqBody .= "$field_bal_1m=$bal_1m&";
            } // CLOSE STATEMENT 25

            if (isset($field_fix_var_1m) && $field_fix_var_1m!=""){ // STATEMENT 26
              $ReqBody .= "$field_fix_var_1m=$fix_var_1m&";
            } // CLOSE STATEMENT 26

            if (isset($field_pay_1m) && $field_pay_1m!=""){ // STATEMENT 27
              $ReqBody .= "$field_pay_1m=$pay_1m&";
            } // CLOSE STATEMENT 27

            if (isset($field_rate_1m) && $field_rate_1m!=""){ // STATEMENT 28
              $ReqBody .= "$field_rate_1m=$rate_1m&";
            } // CLOSE STATEMENT 28

            if (isset($field_rate_2m) && $field_rate_2m!=""){ // STATEMENT 29
              $ReqBody .= "$field_rate_2m=$rate_2m&";
            } // CLOSE STATEMENT 29

            if (isset($field_2m_ind) && $field_2m_ind!=""){ // STATEMENT 30
              $ReqBody .= "$field_2m_ind=$2m_ind&";
            } // CLOSE STATEMENT 30

            if (isset($field_bal_2m) && $field_bal_2m!=""){ // STATEMENT 31
              $ReqBody .= "$field_bal_2m=$bal_2m&";
            } // CLOSE STATEMENT 31

            if (isset($field_pay_2m) && $field_pay_2m!=""){ // STATEMENT 32
              $ReqBody .= "$field_pay_2m=$pay_2m&";
            } // CLOSE STATEMENT 32

            if (isset($field_prop_address) && $field_prop_address!=""){ // STATEMENT 33
              $ReqBody .= "$field_prop_address=$p_address&";
            } // CLOSE STATEMENT 33

            if (isset($field_prop_city) && $field_prop_city!=""){ // STATEMENT 34
              $ReqBody .= "$field_prop_city=$p_city&";
            } // CLOSE STATEMENT 34

            if (isset($field_prop_zip) && $field_prop_zip!=""){ // STATEMENT 35
              $ReqBody .= "$field_prop_zip=$p_zip&";
            } // CLOSE STATEMENT 35

            if (isset($field_prop_state) && $field_prop_state!=""){ // STATEMENT 36
              $ReqBody .= "$field_prop_state=$p_state&";
            } // CLOSE STATEMENT 36

            if (isset($field_borrower_fname) && $field_borrower_fname!=""){ // STATEMENT 37
              $ReqBody .= "$field_borrower_fname=$borrower_fname&";
            } // CLOSE STATEMENT 37

            if (isset($field_borrower_lname) && $field_borrower_lname!=""){ // STATEMENT 38
              $ReqBody .= "$field_borrower_lname=$borrower_lname&";
            } // CLOSE STATEMENT 38

            if (isset($field_d_area) && $field_d_area!=""){ // STATEMENT 39
              $ReqBody .= "$field_d_area=$d_area&";
            } // CLOSE STATEMENT 39

            if (isset($field_d_phone) && $field_d_phone!=""){ // STATEMENT 40
              $ReqBody .= "$field_d_phone=$d_phone&";
            } // CLOSE STATEMENT 40

            if (isset($field_dw_area) && $field_dw_area!=""){ // STATEMENT 41
              $ReqBody .= "$field_dw_area=$dw_area&";
            } // CLOSE STATEMENT 41

            if (isset($field_dw_phone) && $field_dw_phone!=""){ // STATEMENT 42
              $ReqBody .= "$field_dw_phone=$dw_phone&";
            } // CLOSE STATEMENT 42

            if (isset($field_email) && $field_email!=""){ // STATEMENT 43
              $ReqBody .= "$field_email=$email&";
            } // CLOSE STATEMENT 43

            if (isset($field_contact_time) && $field_contact_time!=""){ // STATEMENT 44
              $ReqBody .= "$field_contact_time=$contact_time&";
            } // CLOSE STATEMENT 44

            if (isset($field_emp_status) && $field_emp_status!=""){ // STATEMENT 45
              $ReqBody .= "$field_emp_status=$emp_status&";
            } // CLOSE STATEMENT 45

            if (isset($field_household_income) && $field_household_income!=""){ // STATEMENT 46
              $ReqBody .= "$field_household_income=$household_income&";
            } // CLOSE STATEMENT 46

            if (isset($field_debt_min_pay) && $field_debt_min_pay!=""){ // STATEMENT 47
              $ReqBody .= "$field_debt_min_pay=$debt_min_pay&";
            } // CLOSE STATEMENT 47

            if (isset($field_coborrow_ind) && $field_coborrow_ind!=""){ // STATEMENT 48
              $ReqBody .= "$field_coborrow_ind=$coborrow_ind&";
            } // CLOSE STATEMENT 48

            if (isset($field_coborrow_emp) && $field_coborrow_emp!=""){ // STATEMENT 49
              $ReqBody .= "$field_coborrow_emp=$coborrow_emp&";
            } // CLOSE STATEMENT 49

            if (isset($field_coborrow_fname) && $field_coborrow_fname!=""){ // STATEMENT 50
              $ReqBody .= "$field_coborrow_fname=$coborrow_fname&";
            } // CLOSE STATEMENT 50

            if (isset($field_coborrow_lname) && $field_coborrow_lname!=""){ // STATEMENT 51
              $ReqBody .= "$field_coborrow_lname=$coborrow_lname&";
            } // CLOSE STATEMENT 51

            if (isset($field_affiliate_id) && $field_affiliate_id!=""){ // STATEMENT 52
              $ReqBody .= "$field_affiliate_id=$aid&";
            } // CLOSE STATEMENT 52

            if (isset($field_campaign_id) && $field_campaign_id!=""){ // STATEMENT 53
              $ReqBody .= "$field_campaign_id=$cid&";
            } // CLOSE STATEMENT 53

            // Generate the request header 
            $ContentLength = strlen($ReqBody);

            $ReqHeader = 
            "POST $URI HTTP/1.1n". 
            "Host: $Hostn". 
            "Content-Type: application/x-www-form-urlencodedn". 
            "Content-Length: $ContentLengthnn". 
            "$ReqBodyn". 
            "Connection: closernrn";

            // Open the connection to the host and send the lead
            $socket = fsockopen($Host, 80, &$errno, &$errstr); 

            if (!$socket){ // STATEMENT 54
              $Result["errno"] = $errno;
              $Result["errstr"] = $errstr;
              return $Result;
            } // CLOSE STATEMENT 54

            $idx = 0;
            fputs($socket, $ReqHeader);

            while (!feof($socket)){ // STATEMENT 55
              $Result[$idx++] = fgets($socket, 128);
            } // CLOSE STATEMENT 55

            // Close the connection
            fclose($socket);

            // Update the lead table to show that they lead was matched with a lead buyer
            mysql_query("UPDATE $table SET lead_buyer='$partid' WHERE id='$id'")
            or die(mysql_error());

            // Send the customer to the thank you page.
            print "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php?pg=thankyou'>";	
            die;

          }elseif($method == 'ftp'){ // STATEMENT 14

            // Assign a name and path to save the file
            $filename ="./ftp/liftdebt$id.txt";

            // Open the file for writing
            $myFile= fopen($filename,'w+');

            // Make sure the file was opened successfully
            if(! $myFile){ // STATEMENT 56
              print ("File could not be opened.");
              exit;
            } // CLOSE STATEMENT 56

            // Generate the file contents (Have not edited fields yet)
            $submittedby = "www.liftdebt.com";
            $string = "IP Address: $ip n
            Date Received: $date_received n
            P_Descr:  $p_descr: n
            Credit History:  $cred_hist n
            State:  $p_state n
            Loan Amount: $loan_amount n
            P_Purpose: $p_purpose n
            P_Value:  $p_value n
            LTV: $ltv n
            P_Years:  $p_years n
            Ind_1m:  $ind_1m n
            Bal_1m:  $bal_1m n
            Pay_1m:  $pay_1m n
            Rate_1m:  $rate_1m n
            Fix_Var_1m:  $fix_var_1m n
            Bal_2m:  $bal_2m n
            Pay_2m:  $pay_2m n
            P_Address: $p_address n
            P_City: $p_city n
            P_Zip:  $p_zip n
            Borrower's First Name:  $borrower_fname n
            Borrower's Last Name:  $borrower_lname n
            D_Area:  $d_area n
            D_Phone:  $d_phone n
            DW_Area:  $dw_area n
            DW_Phone:  $dw_phone n
            Email:  $email n
            Employment Status:  $emp_status n
            Household Income:  $household_income n
            Debt_Min_Pay:  $debt_min_pay n
            Contact Time:  $contact_time n
            Ind_Coborrower:  $ind_coborrower n
            Co-borrower's First Name: $coborrower_fname n
            Co-borrower's Last Name:  $coborrower_lname n
            Co-borrower's Employment Status:  $coborrower_emp_status n
            Product:  $product n
            Submitted By: $submittedby n
            ";

            // Write the data to the text file
            fputs($myFile, $string); 

            // Close the file after writing data to it
            fclose($myFile);

            // Connect to the FTP host to upload the file		
            $conn = ftp_connect($Host);

            // Check the connection
            if(!$conn){ // STATEMENT 57
              exit("Could not connect to server: $Hostn");
            } // CLOSE STATEMENT 57

            // Check the login information
            if(!ftp_login($conn,$ftp_username,$ftp_password)){ // STATEMENT 58
              ftp_quit($conn);
              exit("Could not log inn");
            } // CLOSE STATEMENT 58

            // Open the connection and send the file
            ftp_chdir($conn,$URI);

            $files = ftp_nlist($conn,�.�);

            for($i=0;$i<count($files);$i++){

            if(!ftp_get($conn,$files[$i],$files[$i],FTP_ASCII)){ // STATEMENT 59
              echo "Could not download {$files[$i]}n";
            } // CLOSE STATEMENT 59

            if(!ftp_put($conn,$URI.$filename,$filename,FTP_ASCII)){ // STATEMENT 60
              echo "Could not upload $filenamen";
            } // CLOSE STATEMENT 60

            // Close the connection
            ftp_quit($conn);

            // Update the lead table to show that they lead was matched with a lead buyer
            mysql_query("UPDATE $table SET lead_buyer='$partid' WHERE id='$id'")
            or die(mysql_error());

            // Send the customer to the thank you page.
            print "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php?pg=thankyou'>";	
            die;
          } // CLOSE STATEMENT 14
        } // CLOSE STATEMENT 13
      } // CLOSE STATEMENT 11
    } // CLOSE STATEMENT 9
  }elseif($tabid == 2){ // STATEMENT 8
    $p_price = $r['p_price'];
    $m_address = $r['m_address'];
    $m_state = $r['m_state'];
    $m_city = $r['m_city'];
    $m_zip = $r['m_zip'];
    $found_home_type = $r['found_home_type'];
    $down_payment_percent = $r['down_payment_percent'];
    $own_rent_type = $r['own_rent_type'];
    $ind_reagent = $r['ind_reagent'];
    $ind_pcontract = $r['ind_pcontract'];
    $purchase_timeframe = $r['purchase_timeframe'];

    $query2 = mysql_query("SELECT * FROM partner_filters WHERE product='$product' AND AND min_p_price <= '$p_price' AND state='$p_state' ORDER BY cpl LIMIT 0,1");
    $number = mysql_num_rows($query2);

    while($t = mysql_fetch_array($query2)){ // STATEMENT 61
      $partid = $t['partid'];

      if($number == 0){ // STATEMENT 62
        print "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php?pg=sorry'>";
        die;
      } // CLOSE STATEMENT 62

      $query3 = mysql_query("SELECT * FROM partners WHERE id='$partid'");

      while($a = mysql_fetch_array($query3)){ // STATEMENT 63
        $active = $a['active_flag'];
        $Host = $a['post_host'];
        $URI = $a['post_url'];
        $ftp_username = $a['ftp_username'];
        $ftp_password = $a['ftp_password'];
        $method = $a['method'];
        $daily_cap = $a['daily_cap'];
        $aid = $a['affiliate_id'];
        $cid = $a['campaign_id'];

        $query4 = mysql_query("SELECT * FROM refi_leads WHERE lead_buyer='$partid' AND date_received like date('Y-m-d')");
        $num = mysql_num_rows($query4);

        if($active == 0 || $num >= $daily_cap){ // STATEMENT 64
          print "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php?pg=sorry'>";
          die;
        } // CLOSE STATEMENT 64

        $query5 = mysql_query("SELECT * FROM partners_purchase_fields WHERE partid='$partid'");

        while($b = mysql_fetch_array($query5)){ // STATEMENT 65
          $field_ipaddress = $b['field_ipaddress'];
          $field_datereceived = $b['field_datereceived'];
          $field_product = $b['field_product'];
          $field_p_descr = $b['field_p_descr'];
          $field_cred_hist = $b['field_cred_hist'];
          $field_loan_amount = $b['field_p_price'];
          $field_p_purpose = $b['field_p_purpose'];
          $field_p_value = $b['field_p_value'];
          $field_p_years = $b['field_p_years'];
          $field_1m_ind = $b['field_1m_ind'];
          $field_bal_1m = $b['field_bal_1m'];
          $field_fix_var_1m = $b['field_fix_var_1m'];
          $field_pay_1m = $b['field_pay_1m'];
          $field_rate_1m = $b['field_rate_1m'];
          $field_rate_2m = $b['field_rate_2m'];
          $field_2m_ind = $b['field_2m_ind'];
          $field_bal_2m = $b['field_bal_2m'];
          $field_pay_2m = $b['field_pay_2m'];
          $field_prop_address = $b['field_prop_address'];
          $field_prop_city = $b['field_prop_city'];
          $field_prop_state = $b['field_prop_state'];
          $field_prop_zip = $b['field_prop_zip'];
          $field_borrower_fname = $b['field_borrower_fname'];
          $field_borrower_lname = $b['field_borrower_lname'];
          $field_d_area = $b['field_d_area'];
          $field_d_phone = $b['field_d_phone'];
          $field_dw_area = $b['field_dw_area'];
          $field_dw_phone = $b['field_dw_phone'];
          $field_email = $b['field_email'];
          $field_contact_time = $b['field_contact_time'];
          $field_emp_status = $b['field_emp_status'];
          $field_household_income = $b['field_household_income'];
          $field_debt_min_pay = $b['field_debt_min_pay'];
          $field_coborrow_ind = $b['field_coborrow_ind'];
          $field_coborrow_emp = $b['field_coborrow_emp'];
          $field_coborrow_fname = $b['field_coborrow_fname'];
          $field_coborrow_lname = $b['field_coborrow_lname'];
          $field_affiliate_id = $b['field_affiliate_id'];
          $field_campaign_id = $b['field_campaign_id'];

          if($method == 'post'){ // STATEMENT 66

            if (isset($field_datereceived) && $field_datereceived!=""){ // STATEMENT 67
              $ReqBody .= "$field_datereceived=$date_received&";
            } // CLOSE STATEMENT 67

            if (isset($field_ipaddress) && $field_ipaddress!=""){ // STATEMENT 68
              $ReqBody .= "$field_ipaddress=$ip&";
            } // CLOSE STATEMENT 68

            if (isset($field_product) && $field_product!=""){ // STATEMENT 69
              $ReqBody .= "$field_product=$product&";
            } // CLOSE STATEMENT 69

            if (isset($field_p_descr) && $field_p_descr!=""){ // STATEMENT 70
              $ReqBody .= "$field_p_descr=$p_descr&";
            } // CLOSE STATEMENT 70

            if (isset($field_cred_hist) && $field_cred_hist!=""){ // STATEMENT 71
              $ReqBody .= "$field_cred_hist=$cred_hist&";
            } // CLOSE STATEMENT 71

            if (isset($field_loan_amount) && $field_loan_amount!=""){ // STATEMENT 72
              $ReqBody .= "$field_loan_amount=$loan_amount&";
            } // CLOSE STATEMENT 72

            if (isset($field_p_purpose) && $field_p_purpose!=""){ // STATEMENT 73
              $ReqBody .= "$field_p_purpose=$p_purpose&";
            } // CLOSE STATEMENT 73

            if (isset($field_p_value) && $field_p_value!=""){ // STATEMENT 74
              $ReqBody .= "$field_p_value=$p_value&";
            } // CLOSE STATEMENT 74

            if (isset($field_p_years) && $field_p_years!=""){ // STATEMENT 75
              $ReqBody .= "$field_p_years=$p_years&";
            } // CLOSE STATEMENT 75

            if (isset($field_1m_ind) && $field_1m_ind!=""){ // STATEMENT 76
              $ReqBody .= "$field_1m_ind=$1m_ind&";
            } // CLOSE STATEMENT 77

            if (isset($field_bal_1m) && $field_bal_1m!=""){ // STATEMENT 78
              $ReqBody .= "$field_bal_1m=$bal_1m&";
            } // CLOSE STATEMENT 78

            if (isset($field_fix_var_1m) && $field_fix_var_1m!=""){ // STATEMENT 79
              $ReqBody .= "$field_fix_var_1m=$fix_var_1m&";
            } // CLOSE STATEMENT 79

            if (isset($field_pay_1m) && $field_pay_1m!=""){ // STATEMENT 80
              $ReqBody .= "$field_pay_1m=$pay_1m&";
            } // CLOSE STATEMENT 80

            if (isset($field_rate_1m) && $field_rate_1m!=""){ // STATEMENT 81
              $ReqBody .= "$field_rate_1m=$rate_1m&";
            } // CLOSE STATEMENT 81

            if (isset($field_rate_2m) && $field_rate_2m!=""){ // STATEMENT 82
              $ReqBody .= "$field_rate_2m=$rate_2m&";
            } // CLOSE STATEMENT 82

            if (isset($field_2m_ind) && $field_2m_ind!=""){ // STATEMENT 83
              $ReqBody .= "$field_2m_ind=$2m_ind&";
            } // CLOSE STATEMENT 83

            if (isset($field_bal_2m) && $field_bal_2m!=""){ // STATEMENT 84
              $ReqBody .= "$field_bal_2m=$bal_2m&";
            } // CLOSE STATEMENT 84

            if (isset($field_pay_2m) && $field_pay_2m!=""){ // STATEMENT 85
              $ReqBody .= "$field_pay_2m=$pay_2m&";
            } // CLOSE STATEMENT 85

            if (isset($field_prop_address) && $field_prop_address!=""){ // STATEMENT 86
              $ReqBody .= "$field_prop_address=$p_address&";
            } // CLOSE STATEMENT 86

            if (isset($field_prop_city) && $field_prop_city!=""){ // STATEMENT 87
              $ReqBody .= "$field_prop_city=$p_city&";
            } // CLOSE STATEMENT 87

            if (isset($field_prop_zip) && $field_prop_zip!=""){ // STATEMENT 88
              $ReqBody .= "$field_prop_zip=$p_zip&";
            } // CLOSE STATEMENT 88

            if (isset($field_prop_state) && $field_prop_state!=""){ // STATEMENT 89
              $ReqBody .= "$field_prop_state=$p_state&";
            } // CLOSE STATEMENT 89

            if (isset($field_borrower_fname) && $field_borrower_fname!=""){ // STATEMENT 90
              $ReqBody .= "$field_borrower_fname=$borrower_fname&";
            } // CLOSE STATEMENT 90

            if (isset($field_borrower_lname) && $field_borrower_lname!=""){ // STATEMENT 91
              $ReqBody .= "$field_borrower_lname=$borrower_lname&";
            } // CLOSE STATEMENT 91

            if (isset($field_d_area) && $field_d_area!=""){ // STATEMENT 92
              $ReqBody .= "$field_d_area=$d_area&";
            } // CLOSE STATEMENT 92

            if (isset($field_d_phone) && $field_d_phone!=""){ // STATEMENT 93
              $ReqBody .= "$field_d_phone=$d_phone&";
            } // CLOSE STATEMENT 93

            if (isset($field_dw_area) && $field_dw_area!=""){ // STATEMENT 94
              $ReqBody .= "$field_dw_area=$dw_area&";
            } // CLOSE STATEMENT 94

            if (isset($field_dw_phone) && $field_dw_phone!=""){ // STATEMENT 95
              $ReqBody .= "$field_dw_phone=$dw_phone&";
            } // CLOSE STATEMENT 95

            if (isset($field_email) && $field_email!=""){ // STATEMENT 96
              $ReqBody .= "$field_email=$email&";
            } // CLOSE STATEMENT 96

            if (isset($field_contact_time) && $field_contact_time!=""){ // STATEMENT 97
              $ReqBody .= "$field_contact_time=$contact_time&";
            } // CLOSE STATEMENT 97

            if (isset($field_emp_status) && $field_emp_status!=""){ // STATEMENT 98
              $ReqBody .= "$field_emp_status=$emp_status&";
            } // CLOSE STATEMENT 98

            if (isset($field_household_income) && $field_household_income!=""){ // STATEMENT 99
              $ReqBody .= "$field_household_income=$household_income&";
            } // CLOSE STATEMENT 99

            if (isset($field_debt_min_pay) && $field_debt_min_pay!=""){ // STATEMENT 100
              $ReqBody .= "$field_debt_min_pay=$debt_min_pay&";
            } // CLOSE STATEMENT 100

            if (isset($field_coborrow_ind) && $field_coborrow_ind!=""){ // STATEMENT 101
              $ReqBody .= "$field_coborrow_ind=$coborrow_ind&";
            } // CLOSE STATEMENT 101

            if (isset($field_coborrow_emp) && $field_coborrow_emp!=""){ // STATEMENT 102
              $ReqBody .= "$field_coborrow_emp=$coborrow_emp&";
            } // CLOSE STATEMENT 102

            if (isset($field_coborrow_fname) && $field_coborrow_fname!=""){ // STATEMENT 103
              $ReqBody .= "$field_coborrow_fname=$coborrow_fname&";
            } // CLOSE STATEMENT 103

            if (isset($field_coborrow_lname) && $field_coborrow_lname!=""){ // STATEMENT 104
              $ReqBody .= "$field_coborrow_lname=$coborrow_lname&";
            } // CLOSE STATEMENT 104

            if (isset($field_affiliate_id) && $field_affiliate_id!=""){ // STATEMENT 105
              $ReqBody .= "$field_affiliate_id=$aid&";
            } // CLOSE STATEMENT 105

            if (isset($field_campaign_id) && $field_campaign_id!=""){ // STATEMENT 106
              $ReqBody .= "$field_campaign_id=$cid&";
            } // CLOSE STATEMENT 106

            // Generate the request header 
            $ContentLength = strlen($ReqBody);

            $ReqHeader = 
            "POST $URI HTTP/1.1n". 
            "Host: $Hostn". 
            "Content-Type: application/x-www-form-urlencodedn". 
            "Content-Length: $ContentLengthnn". 
            "$ReqBodyn". 
            "Connection: closernrn";

            // Open the connection to the host and send the lead
            $socket = fsockopen($Host, 80, &$errno, &$errstr); 

            if (!$socket){ // STATEMENT 107
              $Result["errno"] = $errno;
              $Result["errstr"] = $errstr;
              return $Result;
            } // CLOSE STATEMENT 107

            $idx = 0;
            fputs($socket, $ReqHeader);

            while (!feof($socket)){ // STATEMENT 108
              $Result[$idx++] = fgets($socket, 128);
            } // CLOSE STATEMENT 108

            // Close the connection
            fclose($socket);

            // Update the lead table to show that they lead was matched with a lead buyer
            mysql_query("UPDATE $table SET lead_buyer='$partid' WHERE id='$id'")
            or die(mysql_error());

            // Send the customer to the thank you page.
            print "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php?pg=thankyou'>";	
            die;

          }elseif($method == 'ftp'){ // STATEMENT 66

            // Assign a name and path to save the file
            $filename ="./ftp/liftdebt$id.txt";

            // Open the file for writing
            $myFile= fopen($filename,'w+');

            // Make sure the file was opened successfully
            if(! $myFile){ // STATEMENT 109
              print ("File could not be opened.");
              exit;
            } // CLOSE STATEMENT 109

            // Generate the file contents
            $submittedby = "www.liftdebt.com";
            $string = "IP Address: $ip n
            Date Received: $date_received n
            P_Descr:  $p_descr: n
            Credit History:  $cred_hist n
            State:  $p_state n
            Loan Amount: $loan_amount n
            P_Purpose: $p_purpose n
            P_Value:  $p_value n
            LTV: $ltv n
            P_Years:  $p_years n
            Ind_1m:  $ind_1m n
            Bal_1m:  $bal_1m n
            Pay_1m:  $pay_1m n
            Rate_1m:  $rate_1m n
            Fix_Var_1m:  $fix_var_1m n
            Bal_2m:  $bal_2m n
            Pay_2m:  $pay_2m n
            P_Address: $p_address n
            P_City: $p_city n
            P_Zip:  $p_zip n
            Borrower's First Name:  $borrower_fname n
            Borrower's Last Name:  $borrower_lname n
            D_Area:  $d_area n
            D_Phone:  $d_phone n
            DW_Area:  $dw_area n
            DW_Phone:  $dw_phone n
            Email:  $email n
            Employment Status:  $emp_status n
            Household Income:  $household_income n
            Debt_Min_Pay:  $debt_min_pay n
            Contact Time:  $contact_time n
            Ind_Coborrower:  $ind_coborrower n
            Co-borrower's First Name: $coborrower_fname n
            Co-borrower's Last Name:  $coborrower_lname n
            Co-borrower's Employment Status:  $coborrower_emp_status n
            Product:  $product n
            Submitted By: $submittedby n
            ";

            // Write the data to the text file
            fputs($myFile, $string); 

            // Close the file after writing data to it
            fclose($myFile);

            // Connect to the FTP host to upload the file		
            $conn = ftp_connect($Host);

            // Check the connection
            if(!$conn){ // STATEMENT 110
              exit("Could not connect to server: $Hostn");
            } // CLOSE STATEMENT 110

            // Check the login information
            if(!ftp_login($conn,$ftp_username,$ftp_password)){ // STATEMENT 111
              ftp_quit($conn);
              exit("Could not log inn");
            } // CLOSE STATEMENT 111

            ftp_chdir($conn,$URI);

            $files = ftp_nlist($conn,�.�);

            for($i=0;$i<count($files);$i++){

            if(!ftp_get($conn,$files[$i],$files[$i],FTP_ASCII)){ // STATEMENT 112
              echo "Could not download {$files[$i]}n";
            } // CLOSE STATEMENT 112

            if(!ftp_put($conn,$URI.$filename,$filename,FTP_ASCII)){ // STATEMENT 113
              echo "Could not upload $filenamen";
            } // CLOSE STATEMENT 113

            ftp_quit($conn);

            // Update the lead table to show that they lead was matched with a lead buyer
            mysql_query("UPDATE $table SET lead_buyer='$partid' WHERE id='$id'")
            or die(mysql_error());

            // Send the customer to the thank you page.
            print "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php?pg=thankyou'>";	
            die;
          } // CLOSE STATEMENT 66
        } // CLOSE STATEMENT 65
      } // CLOSE STATEMENT 63
    } // CLOSE STATEMENT 61
  } // CLOSE STATEMENT 8
} // CLOSE STATEMENT 7

} // CLOSE STATEMENT 6
} // CLOSE STATEMENT 1
?>[/code]


#2

Nevermind, I figured it out. It just took some restructuring and then I realized I had an open for statement.

Thanks for everyone’s help.