简体   繁体   English

Web服务的PHP fedex邮政编码错误

[英]PHP fedex for web services zip code error

So I am trying to integrate fedex for web services in php. 因此,我正在尝试在PHP中将fedex集成到Web服务中。 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. 我所有的代码一直有效,直到我尝试从表单中添加$ postal变量为止,如果我将85308硬编码为'PostalCode'=>'85308',则它可以工作,但是如果我将'85308'替换为'。邮政。'' 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. 我已经在变量上使用trim(),将其名称更改为所有好的内容,但还是不可行。

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 参见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) 使用全局变量(丑陋)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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