Hi everyone!
I haven't been using NuSOAP for very long. I've created a client and server that both work in terms of the client sends a message with a parameter for a method on the server. The server queries a MySQL database and returns some results, An email is then sent to all the names that were returned from the database.
However!
I get the "XML error parsing SOAP payload on line 1: Empty document", and I have no idea of how to get rid of it! The code for the server is:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('MessageWebServicewsdl', 'urn:MessageWebServicewsdl');
// Register the method to expose
$server->register
(
'school', // Method name
array('school' => 'xsd:string'), // input parameters
array('return' => 'xsd:string'),
'urn:MessageWebServicewsdl',
'urn:MessageWebServicewsdl#school',
'rpc',
'encoded',
'Uses the School to find email addresses in the database'
);
// Define The Method As a PHP Function
function School($school)
{
$conn = mysql_connect('databaselocation', 'username', 'password') or die ('Error connecting to mysql');
mysql_select_db('databasename') or die ('Unable to find database');
$query="SELECT * FROM student WHERE school='$school'";
$result=mysql_query($query);
$rows=mysql_num_rows($result);
$i=0;
while ($i < $rows)
{
$name = mysql_result($result, $i, "name");
$email = mysql_result($result, $i, "email");
$school = mysql_result($result, $i, "school");
echo $name . "<br />";
echo $school . "<br />";
$message = "Hello '$name', Well despite some errors showing, it does actually work!";
mail($email, 'Test E-Mail', $message);
$i++;
}
mysql_close($conn);
return 'Message sent to all students in the school of ' . $school;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
|
Any help would be much appreciated!
Cheers, Jonny...