0

I've seen many questions about this same issue, but nothing helps me with this problem.

I'm very new to PHP and i've been trying some things with $_GET requests to a localhost using XAMPP and MySql with good results, but when I use $_POST allways get the same result.

<?php
if(isset($_POST["name"])){
    echo 'Hi ' . $_POST["name"] . '!';
}else{
    echo "null";
}
var_dump($_POST["name"]);
?>
null<br />
<b>Notice</b>:  Undefined index: name in <b>C:\xampp\htdocs\tests\test.php</b> on line <b>8</b><br />
NULL

This is a simple test I've tried. I send POST request using Postman, I give the values in variables but the result is allways the same.

enter image description here

Ron
  • 53
  • 1
  • 7
  • In the example above you are not passing the variables with POST, you are using GET i.e. test.php?name=test (that is a GET request). So to get this variable you would need to use $_GET['name'] – fraggley May 07 '20 at 14:36
  • when dealing with api calls you can also try `file_get_contents('php://input');` to read the imcoming data – Dave May 07 '20 at 14:39
  • @DanLeach, but I've selected the `POST` option from the menu. The `?name= test' i don't know how it gets there. I'll correct the image – Ron May 07 '20 at 14:53
  • 1
    We're not seeing where you're supposedly passing `name` in any way there… – deceze May 07 '20 at 14:59
  • Please post an image showing POST selected and the KEY (name) and VALUE (test) filled in – fraggley May 07 '20 at 15:02
  • @deceze, oh, god, I'm sorry, i was passing parameters in Postman when should be passed on body as key/value options. I should have look better before. – Ron May 07 '20 at 15:29

0 Answers0