我在一個MySQL數據庫中存儲郵政編碼爲varchar(10)
。由於某種原因,將其存儲在一張桌子中並不像另一張桌子那樣工作。這兩個字段之間的唯一區別是一個是varchar(10) Nullable
,另一個是varchar(10)
。 Nullable
列正在保存沒有前導零的郵政編碼,因此'05415'
變爲5415
。這在其他表格中工作得很好。我認爲他們被存儲在同一頁面上,但我似乎無法找到問題。我對PHP不太好,所以我非常感謝這裏的幫助。PHP郵編失去領先零
這是在網站上註冊的功能.... db中的註冊表正在保存帶有前導0的郵政編碼,所以我認爲這是有效的。
$Zip = strip_tags(trim($_POST['MembersZip']));
if (strlen($Zip = trim($Zip)) == 0) {
$isError = true;
print "<script>$('#MembersZip').addClass('error');</script>";
print '<div class="errors">Please enter zip/postal code</div>';
}
if (strlen($Zip = trim($Zip)) < 5) {
$isError = true;
print "<script>$('#MembersZip').addClass('error');</script>";
print '<div class="errors">Zip code must be at least 5 digits</div>';
}
$sql = "INSERT INTO tbl_ecommerce_addresses (
ead_postal_code
) VALUES (
'" . addslashes($Zip) . "'
)";
這就是訂單流程的樣子。這是前導零在被插入之前被刪除的表格。
$fieldName = "BillingZip";
$fieldValue = strip_tags($_POST[$fieldName]);
if (!$fieldValue || strlen($fieldValue = trim($fieldValue)) == 0) {
$isError = true;
print "<script>$('#{$fieldName}').addClass('error');</script>";
print '<div class="errors">Please enter billing zip/postal code</div>';
} else {
$this->fields[$fieldName] = $fieldValue;
$this->record->eod_billing_postal_code = $fieldValue;
}
$Zip = $this->record->eod_billing_postal_code;
if (strlen($Zip = trim($Zip)) < 5) {
$isError = true;
print "<script>$('#BillingZip').addClass('error');</script>";
print '<div class="errors">Billing Zip Code must be at least 5 digits</div>';
}
It looks like this line
$newId = $this->record->insert();
is doing the insert, but when I do a var_dump of $this->record, the zip code still shows the leading 0. The only other thing I can think of is that the payment gateway is changing it somehow.
$paymentType = urlencode("Authorization"); // 'Sale' or 'Authorization'
$firstName = urlencode($this->fields["BillingFirst"]);
$lastName = urlencode($this->fields["BillingLast"]);
$creditCardType = urlencode($this->fields["CardType"]);
$creditCardNumber = urlencode($this->fields["CardNumber"]);
$padDateMonth = urlencode(str_pad($this->fields["CardMonth"], 2, '0', STR_PAD_LEFT));
$expDateYear = urlencode($this->fields["CardYear"]);
$cvv2Number = urlencode($this->fields["CardCode"]);
$address1 = trim(urlencode($this->fields["BillingAddress"]));
$address2 = urlencode($this->fields["BillingAddress2"]);
$city = urlencode($this->fields["BillingCity"]);
$state = urlencode($this->fields["BillingState"]);
$zip = urlencode($this->fields["BillingZip"]);
$country = urlencode($CountryCode); // US or other valid country code
$amount = urlencode($this->fields["PurchasedTotal"]);
$currencyID = urlencode($this->siteConfig->cy_code);
$ipAddress = $main->getIP();
$invoice = substr($this->fields["CardNumber"],-4,4) . substr($this->fields["BillingZip"],0,4) . substr($this->fields["PurchasedTotal"],0,2);
$nvpStr = "&PAYMENTACTION=$paymentType&IPADDRESS=$ipAddress&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber".
"&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&INVNUM=$invoice&FIRSTNAME=$firstName&LASTNAME=$lastName".
"&STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=USD";
要獲得郵政編碼,以顯示正確的,我更新了這個代碼,和0出現了:
$zip = str_pad($order->eod_shipping_postal_code, 5, '0', STR_PAD_LEFT);
你可以'var_dump($ this-> fields)'? – sjagr
'[「ShippingZip」] =>字符串(5)「05154」'看起來是對的。嗯 – jlg
@sjagr我還添加了'var_dump($ this-> record)',但它仍然顯示正確的郵政編碼。我認爲這行'$ newId = $ this-> record-> insert();'是插入數據,但如果郵政編碼顯示罰款時,我傾倒它,那麼問題在哪裏呢? – jlg