我已创建此代码以使用nusoap将数据插入到我的数据库中。一切正常,但数据没有插入我的数据库。
这是代码
require_once('nusoap/nusoap.php');
$server = new soap_server();
$server->configureWSDL('Insert Order', 'urn:InsertOrder');
$server->soap_defencoding = 'utf-8';
$server->register(
'InsertOrder',
array('FirstName' => 'xsd:Testing', 'LastName' => 'xsd:NuSoap'),
array('return' =>'xsd:boolean'),
'urn:InsertOrderwsdl',
'urn:InsertOrderwsdl#InsertOrder',
'rpc',
'literal'
);
function InsertOrder($FirstName, $LastName) {
$connect = mysql_pconnect("localhost","root","");
if ($connect) {
if(mysql_select_db("database", $connect)) {
mysql_query("INSERT INTO myuser SET FirstName='$FirstName', LastName='$LastName'");
return true;
}
}
return false;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
这是wsdl文件:
<definitions targetNamespace="urn:InsertOrder">
<types>
<xsd:schema targetNamespace="urn:InsertOrder">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema></types>
<message name="InsertOrderRequest">
<part name="FirstName" type="xsd:Testing"/>
<part name="LastName" type="xsd:NuSoap"/>
</message>
<message name="InsertOrderResponse">
<part name="return" type="xsd:boolean"/>
</message><portType name="Insert OrderPortType">
<operation name="InsertOrder">
<input message="tns:InsertOrderRequest"/>
<output message="tns:InsertOrderResponse"/>
</operation>
</portType>
<binding name="Insert OrderBinding" type="tns:Insert OrderPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="InsertOrder">
<soap:operation soapAction="urn:InsertOrderwsdl#InsertOrder" style="rpc"/>
<input>
<soap:body use="literal" namespace="urn:InsertOrderwsdl"/>
</input>
<output>
<soap:body use="literal" namespace="urn:InsertOrderwsdl"/>
</output>
</operation></binding>
<service name="Insert Order">
<port name="Insert OrderPort" binding="tns:Insert OrderBinding">
<soap:address location="http://localhost/nuSoap/MyService.php"/>
</port>
</service>
</definitions>
在wsdl文件中,参数和输出都可以。我不明白为什么不将这些数据放入我的数据库?我必须在这里错过一些东西任何人都知道为什么会这样?提前谢谢。
答案 0 :(得分:0)
您的Insert语句似乎更像是更新语句。你能改变吗?
mysql_query("INSERT INTO myuser SET FirstName='$FirstName', LastName='$LastName'");
到
mysql_query("INSERT INTO myuser(FirstName,LastName) values('$FirstName', '$LastName')");
答案 1 :(得分:0)
$sql="INSERT INTO employee (ename) VALUES('".$employee_name."')";
$res=mysql_query($sql);
if($res==true){
return "Employee inserted";
}else{
return "data not inserted";
}
答案 2 :(得分:0)
而不是 array('FirstName'=>'xsd:Testing','LastName'=>'xsd:NuSoap'),
尝试一下 array('FirstName'=>'xsd:string','LastName'=>'xsd:string'),