嗨我無法從我的html form.I需要知道如何從html表單正確獲取數據。其次爲什麼這不起作用?當我點擊「IBM Quote」時,我需要獲得「IBM」的價值。
<!DOCTYPE html>
<html>
<head>
<title>Stock Quote</title>
</head>
<body>
<form action="soapTest.php" method="post">
<button name="IBM" type="submit">IBM Quote</button>
</form>
</body>
</html>
PHP代碼
<?php
$wsdl = "http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl";
$client = new SoapClient($wsdl);
$stock = $_POST["button"];
print $stock;
$parameters= array("request"=>$stock);
$values = $client->GetStockQuote($parameters);
$xml = $values->GetStockQuoteResult;
$currentprice = $xml->Last;
$volume=$xml->Volume;
$percentageChange=$xml->PercentageChange;
if($volume!=null)
print "<br />\n Volume: $volume";
else
print "Volume not set";
if($percentageChange!=null)
print "<br />\n PercentageChange: $percentageChange";
else
print "percentageChange not set";
?>
輸出:
Notice: Undefined index: button in /Applications/XAMPP/xamppfiles/htdocs/soapTest.php on line 6
Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] Object reference not set to an instance of an object. in /Applications/XAMPP/xamppfiles/htdocs/soapTest.php:9 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/soapTest.php(9): SoapClient->__call('GetStockQuote', Array) #1 /Applications/XAMPP/xamppfiles/htdocs/soapTest.php(9): SoapClient->GetStockQuote(Array) #2 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/soapTest.php on line 9
輸入名稱是「IBM」而不是「按鈕」。 –
'$ stock = $ _POST ['IBM'];'會爲你工作。 – Bhavin