kqlambert
kqlambert

Reputation: 2711

PHP fedex for web services zip code error

So I am trying to integrate fedex for web services in php. The form before this gets all the necessary items for the receiver of the package. All my code works all the way up until I try to add the $postal variable from the form, if I hard code 85308 into 'PostalCode' => '85308' it works, but if I replace '85308' with ''.$postal.'' it does not work. it gives me the error Message: Destination postal code missing or invalid.

I have used trim() on the variable changed its name all that good stuff still a no go.

any ideas or opinions would be greatly appreciated my code is below.

Thanks

<?php
//get address information$fname = $_POST["fname"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$state = $_POST["state"];
$address1 = $_POST["address1"];
$address2 = $_POST["address2"];
$postal = $_POST["zip"];
$city = $_POST["city"];
$fullname = $fname." ".$lname;
$fulladdress = $address1." ".$address2;

function addRecipient(){
    $recipient = array(
        'Contact' => array(
            'PersonName' => ''.$fullname.'',
            'CompanyName' => 'Company Name',
            'PhoneNumber' => '9012637906'
        ),
        'Address' => array(
            'StreetLines' => array(''.$fulladdress.''),
            'City' => ''.$city.'',
            'StateOrProvinceCode' => ''.$state.'',
            //'PostalCode' => '85308',
            'PostalCode' => ''.$postal.'',
            'CountryCode' => 'US',
            'Residential' => false)
    );
    return $recipient;                  
}

Upvotes: 0

Views: 1903

Answers (1)

Pekka
Pekka

Reputation: 449763

Inside the function, the variables are outside of your scope. See http://php.net/manual/en/language.variables.scope.php

Solutions:

  • Import the variables inside the function
  • Import the variables as parameters to your function
  • Use globals (ugly)

Upvotes: 1

Related Questions