简体   繁体   中英

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;                  
}

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM