1

Look at the following PHP:

<?php
var_dump($_POST);
?>

I am running this program using the following URL:

http://192.168.2.1:8888/a-s/bootstrap/php/test.php?lookup_word=parrot

And the result I am getting is this:

array(0) { }

What sorcery is this? Why is it returning an empty array while I am feeding it at least one key-value pair?

3
  • 3
    seeing ?lookup_word=parrot, I am guessing you want $_GET instead of $_POST Commented Dec 17, 2015 at 3:40
  • Please learn the concept of $_GET and $_POST . You're mixing up these Commented Dec 17, 2015 at 3:41
  • It's because your not getting the variable you defined in you URL. Commented Dec 17, 2015 at 3:43

3 Answers 3

3

It's because your not getting the variable you defined in your URL.

you should do it like this:

var_dump($_GET['lookup_word']);
Sign up to request clarification or add additional context in comments.

Comments

-1

If you are looking for looking_word parameter in $_POST variable, you won't get it as its part of a GET request and will be available in $_GET. If you want to make it general you can check $_REQUEST variable.

<?php
var_dump($_REQUEST);
?>

As others mentioned, please have a look into the GET and POST concepts and $_GET, $_POST and $_REQUEST variables.

Comments

-1

It's returning an empty array simply because the $_POST array in empty. You have not POSTED any data for $_POST to fetch.

Passing arguments via the URL sets them to $_GET not $_POST to set data to $_POST you have to POST data via an HTML form, curl etc

try

var_dump($_GET);

Also please learn more about $_POST & $_GET

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.