1

I am working first time with PHP and Http Post method. I have written a PHP script and running it on WAMP server. I am testing this script using the Advanced Rest Client for chrome. Following is my PHP script

 <?php

    var_dump($_POST);

    $m             = new MongoClient();
    $db            = $m ->tododb;
    $collection    = $db->tasks;

    $title         = $_POST['title'];
    $description   = $_POST["description"];
    $priority      = $_POST["priority"];
    $status        = $_POST["status"];

    $tmp = array(
        "title"         => $title,
        "description"   => $description,
        "priority"      => $priority,
        "status"        => $status
    );

    $collection->insert($tmp);

    echo "success";
?>

Screenshot of my Post request

But i am getting error in my response. For every index variable in $_POST "Undefined Index" error occurs. Further, on doing var_dump on $_POST i found that the array is empty. Can someone please tell me what is wrong with my code and/or Post request. Screenshot of erroraneous response

Poiz
  • 7,611
  • 2
  • 15
  • 17
Praneet Rohida
  • 278
  • 1
  • 2
  • 10
  • 1
    Possible duplicate of [How to get body of a POST in php?](http://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php) – mim. Dec 10 '16 at 18:08
  • ***For every index variable in $_POST "Undefined Index" error occurs...*** What would want to say with that? You might as well ***C-P*** (*Copy-Paste*) the exact Error Message here **;-)** – Poiz Dec 10 '16 at 19:59

1 Answers1

1

try

$post = file_get_contents('php://input');
$var=$post ['var'];
fabribara
  • 130
  • 3