-1

I want to create web service for update database by SOAP wsdl I try these code:

 require_once('dbconn.php');
 require_once('lib/nusoap.php'); 
 $server = new nusoap_server();
    function editBookData($id,$title,$author_name,$price,$isbn,$category){
      global $dbconn;
      $sql = "UPDATE books SET title = :title, author_name = :author_name, price=:price, isbn=:isbn, category= :category WHERE  id= :id";
      // prepare sql and bind parameters
        $stmt = $dbconn->prepare($sql);
        $stmt->bindParam(':id', $id);
        $stmt->bindParam(':title', $title);
        $stmt->bindParam(':author_name', $author_name);
        $stmt->bindParam(':price', $price);
        $stmt->bindParam(':isbn', $isbn);
        $stmt->bindParam(':category', $category);
        // insert a row
        $stmt->execute();

        // $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $data="Update Success!";
        return json_encode($data);
        $dbconn = null;
    }
$server->configureWSDL('booksServer', 'urn:book');
$server->register('editBookData',
      array('id' => 'xsd:integer'),  //parameter
      array('data' => 'xsd:string'),  //output
      'urn:book',   //namespace
      'urn:book#editBookData' //soapaction
      );  
$server->service(file_get_contents("php://input"));

but seem to be not working, i am new for SOAP API any solution for these problem?

Rajes
  • 103
  • 3
  • 14
  • Hello. It might be worthy to separate the problem into smaller, independent parts. One the SOAP side, the other the database side. So you can tell which side is the one giving you errors? – solarc Nov 07 '18 at 15:42
  • @solarc i already fixed these. thank you – Rajes Nov 12 '18 at 01:18

1 Answers1

-1

I found solution for these error wrong SQL query string.

 $sql = "UPDATE books SET title = '$title', author_name = '$author_name', price='$price', isbn='$isbn', category= '$category' WHERE  id= '$id'";
Rajes
  • 103
  • 3
  • 14
  • This is susceptible of SQL Injection. Don't set the variables directly inside your query. Use the prepare method. Please see https://phpdelusions.net/pdo and ask another question if you still have problems with the SQL part. – solarc Nov 12 '18 at 19:42