0

I am working on simple API and need to use PUT for updating the values in database. I am not able to sent data from the REST client (postman). The following is the code.

switch ($method) {
case 'GET':
    $sql = "select * from trainsample";
    break;
case 'PUT':
    $sql = "UPDATE trainsample SET Name = $_PUT[Name] WHERE ID = $_PUT[ID] ";
    break;
case 'POST':
    $sql = "INSERT INTO trainsample VALUES ('$_POST[ID]','$_POST[Name]','$_POST[Place]','$_POST[Data]')";
    break;
case 'DELETE':
    $sql = "DELETE FROM trainsample WHERE ID = $_DELETE[ID]";
    break;
}

The GET and POST are working fine. But not able to perform PUT and DELETE. Any help is appreciated. Thank you in advance.

4
  • There's no such thing as $_PUT or $_DELETE in PHP. You'll need to parse php://input in your code, PHP doesn't do it automatically except for POST requests. Commented Feb 7, 2017 at 6:27
  • I have tried it also. But no luck Commented Feb 7, 2017 at 6:27
  • In a RESTful API, the parameters are in the URL, not in the data. Commented Feb 7, 2017 at 6:30
  • stackoverflow.com/questions/1538065/find-out-http-method-in-php Commented Feb 7, 2017 at 6:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.