รายละเอียดของการตอบ ::
----------------------------------------------------------------------
ตอนรันหน้าWebServiceClient.php ขึ้นerrorว่า
Undefined index: txtCountry in C:\xampp\htdocs\nusoap\WebServiceClient.php on line 10
----------------------------------------------------------------------
ตอนกดปุ่มsubmit ขึ้นerrorว่า
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\nusoap\WebServiceClient.php on line 45
----------------------------------------------------------------------
หน้าWebServiceClient.php
<html>
<head>
<title>ThaiCreate.Com</title>
</head>
<body>
<form name="frmMain" method="post" action="">
<h2>Search Customer</h2>
Search by Country Code
<input type="text" name="txtCountry" id="txtCountry" value="<?php echo $_POST["txtCountry"];?>">
<input type="submit" name="Submit" value="Submit">
</form>
<?php
if($_POST["txtCountry"] != "")
{
include("lib/nusoap.php");
$client = new nusoap_client("http://localhost/nusoap/WebServiceServer.php?wsdl",true);
$params = array(
'strCountry' => $_POST["txtCountry"]
);
$data = $client->call('resultCustomer', $params);
//echo '<pre>';
//var_dump($data);
//echo '</pre><hr />';
if(count($data) == 0)
{
echo "Not found data!";
}
else
{
?>
<table width="500" border="1">
<tr>
<td>CustomerID</td>
<td>Name</td>
<td>Email</td>
<td>CountryCode</td>
<td>Budget</td>
<td>Used</td>
</tr>
<?php
foreach ($data as $result) {
?>
<tr>
<td><?php echo $result["CustomerID"];?></td>
<td><?php echo $result["Name"];?></td>
<td><?php echo $result["Email"];?></td>
<td><?php echo $result["CountryCode"];?></td>
<td><?php echo $result["Budget"];?></td>
<td><?php echo $result["Used"];?></td>
</tr>
<?php
}
}
}
?>
</body>
</html>
----------------------------------------------------------------------
หน้า WebServiceServer.php
<?php
require_once("lib/nusoap.php");
//Create a new soap server
$server = new soap_server();
//Define our namespace
$namespace = "http://localhost/nusoap/WebServiceServer.php";
$server->wsdl->schemaTargetNamespace = $namespace;
//Configure our WSDL
$server->configureWSDL("getCustomer");
//Add ComplexType
$server->wsdl->addComplexType(
'DataList',
'complexType',
'struct',
'all',
'',
array(
'CustomerID' => array('name' => 'CustomerID', 'type' => 'xsd:string'),
'Name' => array('name' => 'Name', 'type' => 'xsd:string'),
'Email' => array('name' => 'Email', 'type' => 'xsd:string'),
'CountryCode' => array('name' => 'CountryCode', 'type' => 'xsd:string'),
'Budget' => array('name' => 'Budget', 'type' => 'xsd:float'),
'Used' => array('name' => 'Used', 'type' => 'xsd:float')
)
);
//Add ComplexType
$server->wsdl->addComplexType(
'DataListResult',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DataList[]')
),
'tns:DataList'
);
//Register our method and argument parameters
$varname = array(
'strCountry' => "xsd:string"
);
// Register service and method
$server->register('resultCustomer', // method name
$varname, // input parameters
array('return' => 'tns:DataListResult'));
function resultCustomer($strCountry)
{
$objConnect = mysql_connect("localhost","root","123456789") or die(mysql_error());
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer WHERE 1 AND CountryCode like '%".$strCountry."%' ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
return $resultArray;
}
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
?>