$_POST 无法从 HTML 获取数据



嗨,我无法从我的 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
$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"

按钮的名称,因此您必须按该名称调用 post 值。

$stock = $_POST['IBM'];

或者,您可以更改 html 代码,并为按钮指定具有值 IBM 的名称按钮。

<button name="button" value="IBM" type="submit">IBM Quote</button>

相关内容

  • 没有找到相关文章

最新更新