【发布时间】:2015-08-22 11:36:44
【问题描述】:
我想将 Double 值 (i.e. 10.9) 从 HTML 文件传递给 PHP。这是我的 HTML 代码:
<form action="AddProduct.php" method="POST" target="_self">
<table>
<tr>
<label class="lbl"> Title: </label>  
<input class="form-control" type="text" name="title" maxlength="100" size=20>
<label class="lbl"> Price: </label>    
<input class="form-control" type="text" name="price" maxlength=100>
</tr>
<br>
<tr>
<label class="lbl"> Description: </label>   <br>
<textarea rows="10" cols="37" name="description"></textarea>
</tr>
<br>
<tr>
<input class="btn" type="Submit" name="save" value="Save">
</tr>
</table>
</form>
这是我的 PHP 代码:
require __DIR__.'/../vendor/autoload.php';
$config = require __DIR__.'/../configuration.php';
use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;
$siteId = Constants\SiteIds::US;
$service = new Services\TradingService(array(
'apiVersion' => $config['tradingApiVersion'],
'sandbox' => true,
'siteId' => $siteId,
'authToken' => $config['sandbox']['userToken'],
'devId' => $config['sandbox']['devId'],
'appId' => $config['sandbox']['appId'],
'certId' => $config['sandbox']['certId'],
));
$request = new Types\AddFixedPriceItemRequestType();
$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = $config['sandbox']['userToken'];
$item = new Types\ItemType();
$item->Title = urlencode($_POST['title']);
$item->Description = urlencode($_POST['description']);
$item->StartPrice = new Types\AmountType(array('value' => urlencode($_POST['price'])));
$request->Item = $item;
$response = $service->addFixedPriceItem($request);
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("%s: %s\n%s\n\n",
$error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
$error->ShortMessage,
$error->LongMessage
);
}
}
if ($response->Ack !== 'Failure') {
printf("The item was listed to the eBay Sandbox with the Item number %s\n",
$response->ItemID
);
}
致命错误: 未捕获异常 'DTS\eBaySDK\Exceptions\InvalidPropertyTypeException' 并带有消息 '无效的属性类型:DTS\eBaySDK\Trading\Types\AmountType::value 预期的,进来了 /var/www/html/gitsamp/ebay-sdk-examples/vendor/dts/ebay-sdk/src/DTS/eBaySDK/Types/BaseType.php:433 堆栈跟踪:#0 /var/www/html/gitsamp/ebay-sdk-examples/vendor/dts/ebay-sdk/src/DTS/eBaySDK/Types/BaseType.php(263): DTS\eBaySDK\Types\BaseType::ensurePropertyType(' DTS\eBaySDK\Typ...', '价值', '16.99') #1 /var/www/html/gitsamp/ebay-sdk-examples/vendor/dts/ebay-sdk/src/DTS/eBaySDK/Types/BaseType.php(231): DTS\eBaySDK\Types\BaseType->set(' DTS\eBaySDK\Typ...', '值', '16.99') #2 /var/www/html/gitsamp/ebay-sdk-examples/vendor/dts/ebay-sdk/src/DTS/eBaySDK/Types/DoubleType.php(51): DTS\eBaySDK\Types\BaseType->setValues('DTS\eBaySDK\Typ...', Array) #3 /var/www/html/gitsamp/ebay-sdk-examples/vendor/dts/ebay-sdk-trading/src/DTS/eBaySDK/Trading/Types/AmountType.php(49): DTS\eBaySDK\Types\DoubleType->__construct(Array) #4 /var/www/h in /var/www/html/gitsamp/ebay-sdk-examples/vendor/dts/ebay-sdk/src/DTS/eBaySDK/Types/BaseType.php 在第 433 行
【问题讨论】:
-
您需要将价格翻倍吗?
-
urlencode()需要一个字符串,而不是一个数值作为输入。也许错误发生在其他地方? -
stackoverflow.com/questions/3194932/… 将帮助您了解双重类型
-
是的@KTAnj。我想将一个双精度值从 HTML 传递给 PHP。
-
$price= (double) $_POST['price'];你试过了吗?