Odys Posted February 28, 2007 Share Posted February 28, 2007 Hi everyone, I'm a relative noob to PHP and MySQL, and especially to NuSOAP. Well after a few tutorials on using NuSOAP I managed to construct a Client and a Server, both of which work fine until I tried to use MySQL in the functions that would make up the WebService. The client code is working fine (i've tested it with simple hello world messages and it works). Its the server code which is the issue and is displayed below: <?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('homepages.cs.ncl.ac.uk', 'a3101902', 'messWebService') or die ('Error connecting to mysql'); mysql_select_db('a3101902'); $query="SELECT $school FROM student"; $result=mysql_query($query); $rows=mysql_num_rows($result); $i=0; while ($i <= 1)//($i < $rows) { $name = mysql_result($result, $i, "name"); $email = mysql_result($result, $i, "email"); $school = mysql_result($result, $i, "school"); echo $name; echo $school; $message = "Hello $name, This Is A Test Email"; mail($email, 'Test E-Mail', $message); $i++; } return 'Message sent to all students in the school of ' . $school; mysql_close($conn); } // 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); ?> As the code is I get the following error.... XML error parsing SOAP payload on line 2: Invalid document end ??? This can viewed live at http://homepages.cs.ncl.ac.uk/jonathan.olliff-lee/WebServices/MessagingWebService/ForForumViewing/MessagingClient.php If I comment out the lines: $rows=mysql_num_rows($result); and $name = mysql_result($result, $i, "name"); ... through ... to ... mail($email, 'Test E-Mail', $message); Then everything works fine! So i'm guessing the problem is in these lines? Can anyone help? Cheers! ??? Quote Link to comment Share on other sites More sharing options...
willpower Posted February 28, 2007 Share Posted February 28, 2007 NO 1 Never publish your real username nd password to your DB... Yeah, Im guesing now, but I'd try and simply return these values to screen first. I think that the problem is probably being generated in your SQL statement and that it's failing to find any results. I'd certainly place a single ' before and after $school in the select statement also. Quote Link to comment Share on other sites More sharing options...
Odys Posted February 28, 2007 Author Share Posted February 28, 2007 thanks for the advice, just didnt think about it! password has been changed now anyways! there is nothing of any interest in the DB anyways! Cheers! Quote Link to comment Share on other sites More sharing options...
willpower Posted February 28, 2007 Share Posted February 28, 2007 lol...have you managed to echo your contents to screen? That will help you understand what issues the DB is having. Quote Link to comment Share on other sites More sharing options...
Odys Posted February 28, 2007 Author Share Posted February 28, 2007 yer i tried and got the following error.... wsdl error: XML error parsing WSDL from http://homepages.cs.ncl.ac.uk/jonathan.olliff-lee/WebServices/MessagingWebService/MessagingServer.php?wsdl on line 2: Invalid document end I removed the loop and jus tried to echo record 0 Quote Link to comment Share on other sites More sharing options...
Odys Posted March 2, 2007 Author Share Posted March 2, 2007 Solved the problem by changing: $query="SELECT $school FROM student"; to $query="SELECT * FROM student WHERE school='$school'"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.