-1

以下に、クライアントを使用してphpでsoap Webサービスのコードを記述しました。正常に動作しています。実際にはphpを初めて使用するため、htmlページからサーバーのphpサービスにデータを投稿する方法がわかりません。javascriptを使用することでわかっています可能ですが、どのように.....コードまたは役立つリンクによるヘルプをいただければ幸いです。

<?php
require_once "lib/nusoap.php";

function getProd($username,$password) {
   $user = "root";  
$pswd = "root";  
$db = "LOGIN";  
$conn = mysql_connect('localhost', $user, $pswd);  
mysql_select_db($db, $conn);  
//run the query to search for the username and password the match  
$query = "SELECT * FROM PEOPLE WHERE USERNAME = '$username' AND PASSWORD = '$password'";  
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());  
//this is where the actual verification happens  
if(mysql_num_rows($result) > 0)  
  $valid="LoginSucessful";
  else
  $valid="LoginFailed";
  return $valid;
}

$server = new soap_server();
$server->configureWSDL("productlist", "urn:productlist");

$server->register("getProd",
    array("username" => "xsd:string","password" => "xsd:string"),    
    array("return" => "xsd:string"),
    "urn:productlist",
    "urn:productlist#getProd",
    "rpc",
    "encoded",
    "Get a listing of products by category");

if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
$server->service($HTTP_RAW_POST_DATA);





  #client of service#

 <?php
require_once "lib/nusoap.php";
$client = new nusoap_client("http://localhost/expa/productlis.php");
$result = $client->call("getProd",array("category" => "admin","item" => "admin"));



Overall just need to pass parameter to the php function.
4

1 に答える 1

1

ユーザーからデータを取得する方法はいくつかあります。

URL パラメータを介してデータを渡します。

<a href="index.php?foo=bar">Foo equals Bar</a>

<?php 

    $foo = (isset($_GET['foo'])) ? $_GET['foo'] : 'undefined';

    echo "foo equals $foo";
?>

まっすぐなフォーム:

// index.php
// An example form that loops back to itself.
<form action="index.php" method="post" id="the_demo_form">
    <fieldset>
        <label for="foo">Foo</label>
        <input type="text" name="foo">  
    </fieldset>
    <input type="submit"/>
</form>
<pre>
<?php
    // the $_POST global contains the data sent in the request.
    var_dump($_POST);
 ?>
</pre>

Ajax JavaScript を使用してページをリロードせずにデータを送信する必要がある場合は、AJAXを使用します。これは、フォーム送信イベントをキャッチし、ページをリロードせずにフォームを送信する jQuery を使用した例です。

// index.php
// An example form
<form action="index.php" method="post" id="the_demo_form">
    <fieldset>
        <label for="foo">Foo</label>
        <input type="text" name="foo">  
    </fieldset>
    <input type="submit"/>
</form>

<script>
 $(document).ready(function(){
    $("#the_demo_form").submit(function(event){ 
        // This prevents the browser from following the form.
        event.preventDefault();
        // We take the data and send it to server via AJAX.
        $.ajax({
            // set this to server side script
            url : "index.php",
            data : $(this).serialize(),
            success: function(data){
                alert("eureka!");
            }
        });
    });
});
</script>
于 2012-10-19T19:06:44.170 に答える