SOAP Client not displaying the required response

  html, php, soap, web-services, wsdl

In my form, the code should be fetching the data from a specific field in the form (num_of_cups). My server page is working well, generating my wsdl. However, the client page is blank. Server side is supposed to calculate the total by fetching the ‘num_of_cups’ from the form and multiplying it with 60. Thus, should display the total on the client side page.
Someone please helpp!! Its really urgent for my assignment that I need to submit tomorrow.

Here is my client side of the SOAP service (client.php) code :

<?php


      $num_of_cups=$_GET['num_of_cups'];
        
require_once "nusoap/lib/nusoap.php";

      //instatiate client with webservice
        $client = new nusoap_client("http://192.168.1.105:888/Zorbet/calculateserver.php?wsdl");

        //getting error constructor
        $error = $client->getError();

        //check for constructor error
        if ($error){

            echo "<h2>Constructor Error </h2> <pre>" . $error . "</pre>";
        }

   
          //capture values from form
          if (isset($_GET['num_of_cups'])){
             $num_of_cups=$_GET['num_of_cups'];
         
          //call function from server with parameters
          $response = $client -> call("getTotal",array("num_of_cups"=>$num_of_cups));

          //check for fault
          if ($client->fault){

                echo "<h2>Fault </h2>" . print_r($response) . "</pre>";

            }else{

                //get error
                $error = $client->getError();

                //check for error
                if ($error){

                    echo "<h2>Error </h2> <pre>" . $error . "</pre>";

                }else{

                    echo "<center>" . $response . "</center>";
                }
            }
        
      }
       
      ?>

Below is my server side of the SOAP service (calculateserver.php) :

<?php

//require nusoap library
require_once "nusoap/lib/nusoap.php";

//function to calculate total and get total price message
function getTotal($num_of_cups){

     //calculating total
     echo $num_of_cups;
     $total = (60*$num_of_cups);

     //set initial response message to display total
     $message="<h5>Your Total is : ".$total."</h5><br/>";

  
     return $message;

 }

 //instantiate server
$server=new soap_server();

//configure wsdl
$server->configureWSDL("demo","urn:totaldemo");

//register function
$server->register(
   "getTotal",
   array("num_of_cups" => "xsd:decimal"),

   array('return' => 'xsd:decimal'),
   
 'urn:totaldemo#getTotal',
"xsd:demo");


$server->service(file_get_contents("php://input"));

?>

Below is my html page for the form :

<html>
<head>
     <meta charset="UTF-8"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
          type="text/css" media="all"/>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Amatic+SC%3A400%2C700%7CLato%3A400%2C700%2C400italic%2C700italic&amp;ver=4.9.8"
          type="text/css" media="screen"/>
      <link rel="stylesheet" href="zorbet.css" type="text/css" media="screen"/>
    <link rel="stylesheet" href="print.css" type="text/css" media="print"/>

<title>Pass to comann form!</title>
</head>

<body>

    <h2 style="text-align: center; color: orange;">Pass to comann: </h2>
    <table boder="0" width="1000">
    <form method = "GET" action ="totalclient.php">
        <tr><td>
        Full Name : <input type = "text" name="full_name"></br></td></tr>
        <tr><td>
        Flavour : <input type="text" name="flavour"></br></td></tr>
        <tr><td>
        Number of cups(qty) : <input type="Number" name = "num_of_cups"></br></td></tr>
        <tr><td>
        Address <input type="text" name = "h_add"></br></td></tr>
        <tr><td>
        Number : <input type = "Number" name = "c_num"></br></td></tr>
        <tr><td>
        <input type="submit" name="submit" value="add"></br></td></tr>

<tr><td>
        <a href="insertxml.php">
        <input type="button" style="color: red;" value="Delete to comman"></button></a></td></tr>
    </form>
</table>
</body>
</html>

Source: Ask PHP

LEAVE A COMMENT