Explaining the name in php

4

Could someone explain the difference and where can I change it.:

$nome=$_POST['nome'];

This $nome I know that it is default in case to use

<input type="text" name="nome">

More in this case, is it mandatory to have this "nome" in $_POST['nome'] or can I use other names?

I hope you have understood.!

    
asked by anonymous 18.09.2018 / 22:13

3 answers

2

Friend, it's just the opposite. The variable name $nome is totally free, you can name it as you want ex. $banana , however it is good practice to name the variables in order to clarify their content.

Already, the value in the $_POST is dependent on the set value name in its html input.

<!-- este "nome" será o valor incluso em $_POST[] -->
<input type="text" name="nome" />  

------------------------------------------
// contém o valor que o usuário digitar 
// no campo de texto com name="nome"
$_POST['nome']
    
18.09.2018 / 22:18
2

You can change if you want, "_POST ['name']" is the name of the "same" variable declared in PHP.

    
18.09.2018 / 22:18
2

The superglobal array $_POST receives data sent by method HTTP POST , because it is array it has keys associated with values, in case this superglobal array associates the value sent by the form with attribute name of input in your case nome , for example you can change the value of the name attribute of input , but take into account that it will only be accessible in $_POST with the same value.

Example:

<input type="text" name="idade">

Attempting to access $_POST["nome"] will return NULL .

    
18.09.2018 / 22:23