Jump to content

[SOLVED] PHP, MySQL & NuSOAP Problem ???


Odys

Recommended Posts

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!

 

???

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.