您好我无法从我的html表单中获取数据。我首先需要知道如何从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 Code
<?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
答案 0 :(得分:1)
"IBM"
是您的按钮名称,因此您必须按该名称调用帖子值。
$stock = $_POST['IBM'];
或者,您可以更改html代码并为按钮指定名称按钮,其值为IBM。
<button name="button" value="IBM" type="submit">IBM Quote</button>