0

So I am new to Php web services and I am having a problem. So whenever the user wants to make an order, it is supposed to proceed onto next page and info is stored in the database table. However, I am getting the following error

Uncaught SoapFault exception: [Client] looks like we got no XML document in [PATH]

Here is my code:-

<?php
include ("connect.php");
$MealName = trim($_POST['mname']);
$Quantity = trim($_POST['qty']);
$CustName = trim($_POST['cname']);
$SpecialInstructions = trim($_POST['spclinstr']);
$address = trim($_POST['address']);
$phone=trim($_POST['pno']);

// SOAP Request
    $wsdl_url = "http://localhost:40/rest/KFC/service.wsdl";
    $client = new SoapClient($wsdl_url);
    // Execute the web service function defined in service.php on the web service server
    $returnedData = $client->proceedNewRequestBook($MealName,  $Quantity, $CustName, $SpecialInstructions, $address, $phone);    // Pass INPUT PARAMETER
    echo "<br/>Response from server:$returnedData";

    $res = simplexml_load_string($returnedData)or die("Error: Cannot create object");

    print_r($res);

?>

and here is my code for the particular function in server.php

   include ("connection.php");

function proceedNewRequestBook($MealName, $Quantity, $CustName, $SpecialInstructions, $address, $phone)
{
$conn = new mysqli("localhost", "root", "", "KFC");
    if ($conn->connect_error){
        die("Connection failed: ".$conn->connect_error);
    }
    else 
    {
        $todayDate = date("Y-m-d H:i:s");
        $sqlQuery = "INSERT INTO `KFC`.`ordertbl` (OrderID, OrderDATE, CustNAME,CustAdd, PHONE ) VALUES (NULL, '$todayDate', '$CustName', '$address',$phone);";

        if ($conn->query($sqlQuery) === TRUE)
        { 
$xmlResult = <<<XML
<?xml version='1.0' encoding="UTF-8"?>
<BOOK_INSERT>
<BOOK>
<MSG>INSERT SUCCESS</MSG>
<CODE>0</CODE>
</BOOK>
</BOOK_INSERT>
XML;
}
else
{
$qr="Errormessage:". mysqli_error($conn);
$q=$conn->error;
$xmlResult = <<<XML
<?xml version='1.0' encoding="UTF-8"?>
<BOOK_INSERT>
<BOOK>
<MSG>$qr</MSG>
<CODE>$q</CODE>
</BOOK>
</BOOK_INSERT>
XML;
}
mysqli_close($conn);
return $xmlResult;
}
}//func close

what am I doing wrong :/ please help.

  • Probably duplicate of https://stackoverflow.com/questions/11593623/how-to-make-a-php-soap-call-using-the-soapclient-class – jjok Apr 03 '18 at 12:34

1 Answers1

1

You don't need to work directly with XML if you're using SoapClient.

Also, the endpoint will accept a single $request parameter, rather than multiple like you passed.

$response = $client->proceedNewRequestBook($request);

$request should be an object or array with all the parameters that you want to pass to the endpoint, in whatever format is specified by the WSDL.

$request = array(
    'MealName' => $MealName,
    'Quantity' => $Quantity,
    'CustName' => $CustName,
    'SpecialInstructions' => $SpecialInstructions,
    //...
);

$response will be a PHP object that you can just start working with.

jjok
  • 601
  • 5
  • 12