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?
It's because your not getting the variable you defined in your URL.
you should do it like this:
var_dump($_GET['lookup_word']);
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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.