mardi 24 mars 2015

PHP web service mini forum query

i am new to web services kinda thing, and i have a problem that is yet to be solved.


So this is my wsdl



<?xml version ='1.0' encoding ='UTF-8' ?>

<definitions name="Biodata"
targetNamespace="urn:TestNamespace"
xmlns="http://ift.tt/LcBaVt"
xmlns:soap="http://ift.tt/KIQHA2"
xmlns:tns="TestNamespace"
xmlns:xsd="http://ift.tt/tphNwY"
xmlns:soapenc='http://ift.tt/wEYywg'
xmlns:wsdl='http://ift.tt/LcBaVt'>
<message name='insertReplyRequest'>
<part name='reply' element="Biodata"/>
</message>
<portType name='BiodataPortType'>
<operation name='insertReply'>
<input message='tns:insertReplyRequest'>
</operation>
</portType>
<binding name='BiodataBinding' type='tns:BiodataPortType'>
<soap:binding style='rpc' transport='http://ift.tt/LcBaVu'/>
<operation name='insertReply'>
<soap:operation soapAction='insertReply'/>
<input>
<soap:body use='encoded' namespace='urn:examples:biodata'
encodingStyle='http://ift.tt/wEYywg'/>
</input>
</operation>
</binding>

<service name='BiodataService'>
<port name='BiodataPort' binding='tns:BiodataBinding'>
<soap:address location='http://localhost/Kevin/FirstWebService/Asynchronous/server.php'/>
</port>
</service>
</definitions>


and this is file reply.php



<?php
$reply = $_POST["reply"];
$post_id = $_POST["post_id"];
$client = new SoapClient("http://localhost/Kevin/FirstWebService/Asynchronous/biodata.wsdl");
$return = $client->insertReply($reply, $post_id);

header("Location: http://localhost/Kevin/FirstWebService/Asynchronous/reply.html");
die();
?>


reply.html is:



<!DOCTYPE html>
<html>
<head>
<title>Reply</title>
</head>

<form action="reply.php" method=POST>
REPLY:<br>
<input type="text" name="reply">
<br>
POST ID<br>
<input type="text" name="post_id">
<br>

<input type="submit" value="Submit">
</form>

</html>


the function is as following:



<?php
function insertReply($reply, $post_id){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "structure2";

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO reply (reply, post_id) VALUES ('$reply', '$post_id')";

$result = $conn->query($sql);

} ?>


and the server:



<?php
require 'biodata_functions.php';
//require 'SoapFault.php';

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("http://localhost/Kevin/FirstWebService/Asynchronous/biodata.wsdl");
/*$server->addFunction("getName");
*/
$server->addFunction("insertPost");
$server->addFunction("insertReply");
$server->handle();

?>


my problem is, i can't insert the $post_id simultaneously with the $reply, and whenever i do, it ends up black in the sql table. is something wrong with my query? or something wrong with my logic? any help will be appreciated, thanks





Aucun commentaire:

Enregistrer un commentaire