Parameter passing in the SOAP web-service

0

Developed a web-service to list students in a class. Insert, List are ok. How much to Delete are not occurring.

codelist.php

<?php//clienteinclude"cliente.php";      

    //chamada do metodo SOAP
    $result = $client->call('listaAlunos');
    //var_dump($result);

?>

    <!DOCTYPE html>
    <html>
    <head>
        <title>Data List</title>
    </head>
    <body>
        <div style="width: 500px; margin: 20px auto;">
            <a href="criar.php">Criar Novo Usuário</a>
            <table width="100%" cellpadding="5" cellspacing="1" border="1">
                <tr>
                    <td>Name</td>
                    <td>Email</td>
                    <td>Address</td>
                    <td>Action</td>
                </tr>
                <?php foreach($result as $row) {?>
                <tr>
                    <td><?php echo $row['name'];?></td>
                    <td><?php echo $row['email'];?></td>
                    <td><?php echo $row['address'];?></td>
                    <td>
                        <a href="editar.php?id=<?php echo $row['id'];?>">Edit</a> | 
                        <a href="deletar.php?id=<?php echo $row['id'];?>" onclick="return confirm('Confirmar Exclusao ?');">Delete</a>
                    </td>
                </tr>
                <?php } ?>
            </table>
            <a href="http://webservicesoap.azurewebsites.net/app5">Back</a>
        </div>
    </body>
    </html>

code deletar.php

// Includs client to get $client object
include 'cliente.php';

$id = $_GET['id']; // id from url
$result = $client->call('excluirAluno',$id);

var_dump ($id);
var_dump ($result);

if( $result ){
    $message = "Record is deleted successfully.";
}else {
    $message = "Sorry, Record is not deleted.";
}

echo $message;
?>

server.php code

<?php
    //server
    //inclusao do arquivo NUSOAP
    require_once('conectar.php');
    require_once('lib/nusoap.php');

    //criacao de uma instanca do servidor
    $server = new soap_server;


    //registro do método
    $server->register('listaAlunos');
    $server->register('inserirAluno');
    $server->register('editarAluno');
    $server->register('excluirAluno');
    $server->register('getById');



    //funcao lista produtos
    function listaAlunos(){

        $con = conectar();

        $sql = "select * from student";
        $result = mysqli_query($con,$sql);

        $produtos = array();

        $linha = mysqli_fetch_assoc($result);
        $total = mysqli_num_rows($result);

        $i =0;
        if($total > 0) {
            do {
                // echo "<br> Codigo:".$linha['codigo']." Produto: ".$linha['nome'];
                 $produtos[$i] = $linha;
                 $i++;
            }while($linha = mysqli_fetch_assoc($result));
        }

        return $produtos;
    }

    function inserirAluno($name, $email, $address){
        $con = conectar();
        $sql = "INSERT INTO student (id, name, email, address) VALUES (null, '$name', '$email', '$address')";
        $result = mysqli_query($con,$sql);
        return $result;
    }

    function editarAluno($id, $name, $email, $address){
        $result = mysqli_query("UPDATE student SET name='$name', email='$email', address='$address' WHERE id=$id");
        return $result;
    }

    function excluirAluno($id){
        $result = mysqli_query("DELETE FROM student WHERE id='$id'");
        return $result;
    }

    function getById($id){
        $result = mysqli_query("SELECT * FROM student WHERE id='$id'");
        return $result;
    }


    //requisição para uso do serviço
    if ( !isset( $HTTP_RAW_POST_DATA ) ) 
        $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );

    $server->service($HTTP_RAW_POST_DATA);

?>
    
asked by anonymous 03.06.2017 / 22:51

1 answer

0

The errors are in the client: deletar.php , I have not correctly passed the array:

$result = $client->call('excluirAluno',array('id' =>$id));

In the server that was served, there were specific errors, it was not creating the connection to the database:

//função para excluir Aluno
    function excluirAluno($id){
        $con = conectar();
        $sql = "DELETE FROM student WHERE id='$id'";
        $result = mysqli_query($con,$sql);
        return $result;
    }

Crud is running here: CrudWebServiceSoapPHP

    
03.06.2017 / 23:30