Passing parameters on the SOAP web-service

Asked

Viewed 550 times

0

I have developed a web-service to list students from a class. Insert, List are ok. As to Delete are not occurring.

inserir a descrição da imagem aqui

code list.php

<?php
    //cliente
    include "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 delete.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);

?>

1 answer

0


Mistakes are in the customer: delete.php, I did not correctly pass as parameter the array:

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

No served had punctual errors, was not creating connection with the bank:

//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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.