1

I'm trying to use the inbuilt this->input->post('name') function when creating the Sign Up API in CodeIgniter, but this->input->post() returns an empty array.

I am using the same url on the browser and it works perfectly fine there but when I try to use it on Postman, it is returning null

I had tried:

print_r($_POST).

I had also used POST And GET Method but show nothing.

which also gives null

For testing purpose I created a function in which I used the form and post method to send data that worked fine on the browser but showed nothing on Postman.

**TESTING Function**
public function test()
{
    echo '<form method="POST"> <input name="name" ><input type="submit"> </form>';
    // print_r($_POST);
    die(var_dump($_POST));
}

On Postman

On Browser

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
Naqvi
  • 13
  • 5

2 Answers2

0

CodeIgniter sometimes acts crazy while getting application/json post values. You can use

$_POST = file_get_contents('php://input');

You will get an array of post values received from Postman with Content-type: application/json header.

  • I have also used ***$_POST = json_decode(file_get_contents("php://input"), true);*** this but it show nothing. – Naqvi Feb 28 '23 at 12:16
-1

Verify your Postman request body: Make sure that you are sending the correct data in the request body. You can check this by opening the "Body" tab in Postman and checking the "form-data" key-value pairs or "raw" body.

Check your CodeIgniter code: Make sure that your CodeIgniter code is correctly configured to accept POST requests. In CodeIgniter, you can use the $this->input->post() function to retrieve data from a POST request. Make sure that you are using this function correctly and that your CodeIgniter controller is correctly set up.

Check your Postman request headers: Make sure that your request headers include Content-Type: application/x-www-form-urlencoded or Content-Type: multipart/form-data. This tells the server that you are sending form data.

Debug your CodeIgniter code: You can add var_dump($_POST) or var_dump($this->input->post()) in your CodeIgniter controller to see if the data is being sent and received correctly. If you are still having trouble, you can use CodeIgniter's debugging tools to help you diagnose the issue.