0

Hi I am unable to get the data from my html form.I need to know firstly how to get data correctly from html forms. Secondly why this is not working? I need to get the value "IBM" when I click "IBM Quote".

<!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";

?>

Output:

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

1 Answers1

1

"IBM" is the name of your button, so you have to call the post value by that name.

$stock = $_POST['IBM'];

Alternatively, you can change your html code and give the button the name button with the value IBM.

<button name="button" value="IBM" type="submit">IBM Quote</button>
Jerodev
  • 32,252
  • 11
  • 87
  • 108
  • Second one is working but first one giving: 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 /Applications/XAMPP/xamppfiles/htdocs/soapTest.php – M Mushfe Rah Jun 09 '17 at 15:28