-1

Below i have written code of a soap webservice in php with its client,It is working fine, actually m new to php so don't know how to post data to my server php service from html page, i know by using javascript it is possible but how.....any help by code or helpful link will be appreciated.

<?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.
Santosh
  • 124
  • 2
  • 13
  • On a side note: You got a pretty serious SQL injection attack vulnerability since you are using unfilted user input in a query. – max Oct 19 '12 at 18:23

1 Answers1

1

There are few ways to get data from the user:

Pass data via url parameters:

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

<?php 

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

    echo "foo equals $foo";
?>

A straight up form:

// 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 If you need to submit the data without reloading via javascript the page you would use AJAX. This is an example using jQuery that catches the form submit event and sends the form without reloading the page.

// 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>
max
  • 96,212
  • 14
  • 104
  • 165