An example of a simple Get and Post request

I only know the basics in php. Now I need to work on requests. I just want to see examples of processing these requests and how it works. Thought about it:

 echo ", $_GET['name'] !";

In the browser, I enter http://localhost/script.php?name=Vasiliy. It seems to be “Hi Vasiliy”, but an error occurs:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in Z:\home\localhost\www\get.php on line 2

What’s wrong? Please provide examples of simple Get and Post requests. I do not plan to use forms yet, I want to use the address bar of the browser. And please don’t forget to comment. ))

Answer 1, authority 100%

echo ", $_GET[name] !"; //  
echo ', '.$_GET['name'].' !'; //  

Answer 2, authority 33%

$_GET – global array for get requests.

$_POST – global array for post requests.

$_REQUEST – global array for get and post requests.




echo $_GET['var'];//hello
echo $_REQUEST['var'];//hello
echo $_POST['var'];//Notice: Undefined index: var in ...

Answer 3

 echo ", {$_GET['name']} !";

We need to escape the variable in this case, following this example. Good luck.