Search code examples
phpserverrequestpostman

PHP post request, receiving always null value


I'm experimenting with some PHP code, not so expert... I'm a beginner in PHP so please forgive me.

I wrote this simple code:


<?php
echo("test");
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    $name = $_POST['fname'];
    if (empty($name)) {
      echo "Name is empty";
      var_dump($name);
    } else {
      echo $name;
    }
} else {
    echo("IS A GET");
}
?>

i'am using postman to send a POST request but looks like the parm I send Is always NULL.

is it something wrong on my code?

postman thanks


Solution

  • Your PostMan request is wrong. You've added your field as a query parameter. Instead switch to the 'Body' tab, select form-data and add your field there.

    enter image description here