Explanation of name in php

Asked

Viewed 134 times

4

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

$nome=$_POST['nome'];

That one $nome I know it’s standard in case I use

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

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

I hope you understand.!

3 answers

2


Friend, it’s just the opposite. The variable name $nomeis totally free, you can name her as you want ex. $banana, however it is good practice to name variables in order to make clear their content.

Already, the value in constant $_POSTis dependent on the set value parameter name in your 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']

2

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

Example:

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

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

1

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.